forked from nette/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatetime.texy
More file actions
79 lines (65 loc) · 2.25 KB
/
datetime.texy
File metadata and controls
79 lines (65 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
Date and Time - Nette\Utils\DateTime
*************************************
.[perex]
[Nette\Utils\DateTime |api:] is a static class extends [php:datetime] with useful functions for working with date and time.
All examples assume the following class alias is defined:
/--php
use Nette\Utils\DateTime;
\--
Let´s take a look how it´s simple.
/--php
$netteRelease = DateTime::from('2006-01-23 10:54:00'); // create from string
$netteRelease->modify('+10 years, 1 month'); // add 10 years and 1 month
echo $netteRelease; // 2016-02-23 10:54:00
\--
/--php
$birthday = DateTime::createFromFormat('d.m.Y', '26.02.1994'); // create from custom format
echo $birthday->getTimestamp(); // 762265863
\--
.[note]
modify is method from parent class [php:datetime]
from($time)
----------
Create [Nette\Utils\DateTime |api:] instance from string, integer or other implementations of [php:datetime] and setup default timezone.
/--php
DateTime::from(1138013640); // create from timestamp
DateTime::from(42); // create from current time and add 42 seconds
DateTime::from('1994-02-26 04:15:32'); // create from date and time
DateTime::from('1994-02-26'); // create from date then fill zeroes
\--
createFromFormat($format, $time, $timezone = NULL)
--------------------------------------------------
Extends //from// method for set custom format and timezone.
/--php
DateTime::createFromFormat('d.m.Y', '26.02.1994'); // create from custom format and default timezone
DateTime::createFromFormat('d.m.Y', '26.02.1994', 'Europe/London'); // create with custom timezone
DateTime::createFromFormat('j. n. Y H:i', '8. 9. 2042 16:36'); // other example
\--
setTimestamp($timestamp)
------------------------
/--php
$created = new DateTime();
$created->setTimestamp(1138013640);
\--
getTimestamp()
--------------
/--php
$publicDate = DateTime::from('2017-02-03');
$publicDate->getTimestamp(); //1486076400
\--
modifyClone($modify = '')
-------------------------
Create independent copy of current instance.
/--php
$created = DateTime::from('2017-02-03');
$public = $created->modifyClone('+1 day');
echo $created; // 2017-02-03
echo $public; // 2017-02-04
\--
jsonSerialize()
---------------
Get string in standard ISO 8601 (used by JavaScript).
/--php
$iso = DateTime::from('2017-02-03');
echo $iso->jsonSerialize();
\--