You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: book/src/date-and-time.md
+12-2
Original file line number
Diff line number
Diff line change
@@ -13,7 +13,7 @@ now() + 40 days
13
13
now() - 1 million seconds
14
14
15
15
# How many days are left until September 1st?
16
-
datetime("2024-11-01 12:30:00") - now() -> days
16
+
date("2024-11-01") - today() -> days
17
17
18
18
# What time is it in Nepal right now?
19
19
now() -> tz("Asia/Kathmandu") # use tab completion to find time zone names
@@ -58,7 +58,9 @@ April 1st"?
58
58
The following functions are available for date and time handling:
59
59
60
60
-`now() -> DateTime`: Returns the current date and time.
61
-
-`datetime(input: String) -> DateTime`: Parses a string into a `DateTime` object.
61
+
-`today() -> DateTime`: Returns the current date at midnight (in the local time).
62
+
-`datetime(input: String) -> DateTime`: Parses a string (date and time) into a `DateTime` object.
63
+
-`date(input: String) -> DateTime`: Parses a string (only date) into a `DateTime` object.
62
64
-`format_datetime(format: String, dt: DateTime) -> String`: Formats a `DateTime` object as a string. See [this page](https://docs.rs/chrono/latest/chrono/format/strftime/index.html#specifiers) for possible format specifiers.
63
65
-`tz(tz: String) -> Fn[(DateTime) -> DateTime]`: Returns a timezone conversion function, typically used with the conversion operator (`datetime -> tz("Europe/Berlin")`)
64
66
-`local(dt: DateTime) -> DateTime`: Timezone conversion function targeting the users local timezone (`datetime -> local`)
@@ -85,3 +87,11 @@ zone is specified, the local time zone is used.
85
87
|`%Y/%m/%d %I:%M:%S%.f %p`| same, but with `/` separator |
86
88
|`%Y-%m-%d %I:%M %p`|`2024-02-10 12:30 PM`<br>`2024-02-10 06:30 AM -0600`<br>`2024-02-10 07:30 AM US/Eastern`|
87
89
|`%Y/%m/%d %I:%M %p`| same, but with `/` separator |
90
+
91
+
The `date` function supports the following formats. It returns a `DateTime` object with the time set to midnight in the
92
+
specified timezone (or the local timezone if no timezone is specified).
0 commit comments