1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel; |
4
|
|
|
|
5
|
|
|
use DateTimeImmutable; |
6
|
|
|
use PhpOffice\PhpSpreadsheet\Calculation\Functions; |
7
|
|
|
|
8
|
|
|
class Current |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* DATENOW. |
12
|
|
|
* |
13
|
|
|
* Returns the current date. |
14
|
|
|
* The NOW function is useful when you need to display the current date and time on a worksheet or |
15
|
|
|
* calculate a value based on the current date and time, and have that value updated each time you |
16
|
|
|
* open the worksheet. |
17
|
|
|
* |
18
|
|
|
* NOTE: When used in a Cell Formula, MS Excel changes the cell format so that it matches the date |
19
|
|
|
* and time format of your regional settings. PhpSpreadsheet does not change cell formatting in this way. |
20
|
|
|
* |
21
|
|
|
* Excel Function: |
22
|
|
|
* TODAY() |
23
|
|
|
* |
24
|
|
|
* @return mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object, |
25
|
|
|
* depending on the value of the ReturnDateType flag |
26
|
|
|
*/ |
27
|
1 |
|
public static function today() |
28
|
|
|
{ |
29
|
1 |
|
$dti = new DateTimeImmutable(); |
30
|
1 |
|
$dateArray = date_parse($dti->format('c')); |
31
|
|
|
|
32
|
1 |
|
return is_array($dateArray) ? Helpers::returnIn3FormatsArray($dateArray, true) : Functions::VALUE(); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* DATETIMENOW. |
37
|
|
|
* |
38
|
|
|
* Returns the current date and time. |
39
|
|
|
* The NOW function is useful when you need to display the current date and time on a worksheet or |
40
|
|
|
* calculate a value based on the current date and time, and have that value updated each time you |
41
|
|
|
* open the worksheet. |
42
|
|
|
* |
43
|
|
|
* NOTE: When used in a Cell Formula, MS Excel changes the cell format so that it matches the date |
44
|
|
|
* and time format of your regional settings. PhpSpreadsheet does not change cell formatting in this way. |
45
|
|
|
* |
46
|
|
|
* Excel Function: |
47
|
|
|
* NOW() |
48
|
|
|
* |
49
|
|
|
* @return mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object, |
50
|
|
|
* depending on the value of the ReturnDateType flag |
51
|
|
|
*/ |
52
|
2 |
|
public static function now() |
53
|
|
|
{ |
54
|
2 |
|
$dti = new DateTimeImmutable(); |
55
|
2 |
|
$dateArray = date_parse($dti->format('c')); |
56
|
|
|
|
57
|
2 |
|
return is_array($dateArray) ? Helpers::returnIn3FormatsArray($dateArray) : Functions::VALUE(); |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|