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
|`%Y-%m-%d %I:%M:%S%.f %p`|`2024-02-10 12:30:00 PM`<br>`2024-02-10 06:30:00 AM -0600`<br>`2024-02-10 07:30:00 AM US/Eastern`<br>`2024-02-10 12:30:00.123456 PM`|
45
-
|`%Y/%m/%d %I:%M:%S%.f %p`| same, but with `/` separator |
46
-
|`%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`|
47
-
|`%Y/%m/%d %I:%M %p`| same, but with `/` separator |
48
29
30
+
# How long are one million seconds in days, hours, minutes, seconds
31
+
1 million seconds // human
32
+
```
49
33
50
34
## Date and time arithmetic
51
35
52
36
The following operations are supported for `DateTime` objects:
53
37
54
38
| Left | Operator | Right | Result |
55
39
| ---- | -------- | ----- | ------ |
56
-
|`DateTime`|`-`|`DateTime`| Duration between the two dates as a `Time`|
40
+
|`DateTime`|`-`|`DateTime`| Duration between the two dates as a `Time`. In `seconds`, by default. Use normal conversion for other time units.|
57
41
|`DateTime`|`+`|`Time`| New `DateTime` by adding the duration to the date |
58
42
|`DateTime`|`-`|`Time`| New `DateTime` by subtracting the duration from the date |
59
-
|`DateTime`|`->`|`String`| Converts the datetime to the specified time zone |
43
+
|`DateTime`|`->`|`String`| Converts the datetime to the specified time zone. Note that you can use tab-completion for time zone names. |
44
+
45
+
<divclass="warning">
60
46
61
-
## Date and time functions
47
+
**Warning**: You can add `years` or `months` to a given date (`now() + 3 months`), but note that the result might not be what you expect.
48
+
The unit `year` is defined as the *average* length of a year (a [tropical year](https://en.wikipedia.org/wiki/Tropical_year), to be precise), and
49
+
`month` is defined as the *average* length of a month (1/12 of a `year`). So this does not take into account the actual length of the months or the leap years.
50
+
However, note that adding or subtracting "one year" or "one month" is not a well-defined operation anyway. For example, what should "one month after March 31st"
51
+
be? April 30th or May 1st? If your answer is April 30th, then what is "one month after March 30th"? If your answer is May 1st, then what is "one month after
52
+
April 1st"?
53
+
54
+
</div>
55
+
56
+
## Date, time, and duration functions
62
57
63
58
The following functions are available for date and time handling:
64
59
65
60
-`now() -> DateTime`: Returns the current date and time.
66
61
-`parse_datetime(input: String) -> DateTime`: Parses a string into a `DateTime` object.
67
-
-`format_datetime(format: String, dt: DateTime) -> String`: Formats a `DateTime` object as a string.
62
+
-`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.
68
63
-`to_unixtime(dt: DateTime) -> Scalar`: Converts a `DateTime` to a UNIX timestamp.
69
64
-`from_unixtime(ut: Scalar) -> DateTime`: Converts a UNIX timestamp to a `DateTime` object.
65
+
-`human(duration: Time) -> String`: Converts a `Time` to a human-readable string in days, hours, minutes and seconds
66
+
67
+
## Date time formats
68
+
69
+
The following formats are supported by `parse_datetime`. UTC offsets are mandatory for the RFC 3339 and
70
+
RFC 2822 formats. The other formats can optionally include a time zone name or UTC offset. If no time
0 commit comments