mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
time: add Time.format_rfc3339() method
This commit is contained in:
parent
3ea9e3aba9
commit
2ecb892985
@ -20,6 +20,13 @@ pub fn (t Time) format_ss_milli() string {
|
|||||||
return '${t.year:04d}-${t.month:02d}-${t.day:02d} ${t.hour:02d}:${t.minute:02d}:${t.second:02d}.${(t.microsecond / 1000):03d}'
|
return '${t.year:04d}-${t.month:02d}-${t.day:02d} ${t.hour:02d}:${t.minute:02d}:${t.second:02d}.${(t.microsecond / 1000):03d}'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// format_rfc3339 returns a date string in "YYYY-MM-DDTHH:mm:ss.123Z" format (24 hours, see https://www.rfc-editor.org/rfc/rfc3339.html)
|
||||||
|
// RFC3339 is an Internet profile, based on the ISO 8601 standard for for representation of dates and times using the Gregorian calendar.
|
||||||
|
// It is intended to improve consistency and interoperability, when representing and using date and time in Internet protocols.
|
||||||
|
pub fn (t Time) format_rfc3339() string {
|
||||||
|
return '${t.year:04d}-${t.month:02d}-${t.day:02d}T${t.hour:02d}:${t.minute:02d}:${t.second:02d}.${(t.microsecond / 1000):03d}Z'
|
||||||
|
}
|
||||||
|
|
||||||
// format_ss_micro returns a date string in "YYYY-MM-DD HH:mm:ss.123456" format (24h).
|
// format_ss_micro returns a date string in "YYYY-MM-DD HH:mm:ss.123456" format (24h).
|
||||||
pub fn (t Time) format_ss_micro() string {
|
pub fn (t Time) format_ss_micro() string {
|
||||||
return '${t.year:04d}-${t.month:02d}-${t.day:02d} ${t.hour:02d}:${t.minute:02d}:${t.second:02d}.${t.microsecond:06d}'
|
return '${t.year:04d}-${t.month:02d}-${t.day:02d} ${t.hour:02d}:${t.minute:02d}:${t.second:02d}.${t.microsecond:06d}'
|
||||||
|
@ -93,6 +93,10 @@ fn test_format_ss_milli() {
|
|||||||
assert '1980-07-11 21:23:42.123' == time_to_test.format_ss_milli()
|
assert '1980-07-11 21:23:42.123' == time_to_test.format_ss_milli()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn test_format_rfc3339() {
|
||||||
|
assert '1980-07-11T21:23:42.123Z' == time_to_test.format_rfc3339()
|
||||||
|
}
|
||||||
|
|
||||||
fn test_format_ss_micro() {
|
fn test_format_ss_micro() {
|
||||||
assert '11.07.1980 21:23:42.123456' == time_to_test.get_fmt_str(.dot, .hhmmss24_micro,
|
assert '11.07.1980 21:23:42.123456' == time_to_test.get_fmt_str(.dot, .hhmmss24_micro,
|
||||||
.ddmmyyyy)
|
.ddmmyyyy)
|
||||||
|
Loading…
Reference in New Issue
Block a user