5 ms·
It is going to be at 2020-09-13 12:26:40 UTC. Python: $ python3 -q >>> from datetime import datetime >>> datetime.utcfromtimestamp(1_600_000_000) date
by susam 6y ago
It is going to be at 2020-09-13 12:26:40 UTC.
Python:
$ python3 -q
>>> from datetime import datetime
>>> datetime.utcfromtimestamp(1_600_000_000)
datetime.datetime(2020, 9, 13, 12, 26, 40)
GNU date (Linux):
$ date -ud @1600000000
Sun Sep 13 12:26:40 UTC 2020
BSD date (macOS, FreeBSD, OpenBSD, etc.):
$ date -ur 1600000000
Sun Sep 13 12:26:40 UTC 2020
All such dates (in UTC) until the end of the current century:
$ python3 -q
>>> from datetime import datetime
>>> for t in range(0, 4_200_000_000, 100_000_000): print(f'{t:13_d} - {datetime.utcfromtimestamp(t).strftime("%Y-%m-%d %H:%M:%S")}')
...
0 - 1970-01-01 00:00:00
100_000_000 - 1973-03-03 09:46:40
200_000_000 - 1976-05-03 19:33:20
300_000_000 - 1979-07-05 05:20:00
400_000_000 - 1982-09-04 15:06:40
500_000_000 - 1985-11-05 00:53:20
600_000_000 - 1989-01-05 10:40:00
700_000_000 - 1992-03-07 20:26:40
800_000_000 - 1995-05-09 06:13:20
900_000_000 - 1998-07-09 16:00:00
1_000_000_000 - 2001-09-09 01:46:40
1_100_000_000 - 2004-11-09 11:33:20
1_200_000_000 - 2008-01-10 21:20:00
1_300_000_000 - 2011-03-13 07:06:40
1_400_000_000 - 2014-05-13 16:53:20
1_500_000_000 - 2017-07-14 02:40:00
1_600_000_000 - 2020-09-13 12:26:40
1_700_000_000 - 2023-11-14 22:13:20
1_800_000_000 - 2027-01-15 08:00:00
1_900_000_000 - 2030-03-17 17:46:40
2_000_000_000 - 2033-05-18 03:33:20
2_100_000_000 - 2036-07-18 13:20:00
2_200_000_000 - 2039-09-18 23:06:40
2_300_000_000 - 2042-11-19 08:53:20
2_400_000_000 - 2046-01-19 18:40:00
2_500_000_000 - 2049-03-22 04:26:40
2_600_000_000 - 2052-05-22 14:13:20
2_700_000_000 - 2055-07-24 00:00:00
2_800_000_000 - 2058-09-23 09:46:40
2_900_000_000 - 2061-11-23 19:33:20
3_000_000_000 - 2065-01-24 05:20:00
3_100_000_000 - 2068-03-26 15:06:40
3_200_000_000 - 2071-05-28 00:53:20
3_300_000_000 - 2074-07-28 10:40:00
3_400_000_000 - 2077-09-27 20:26:40
3_500_000_000 - 2080-11-28 06:13:20
3_600_000_000 - 2084-01-29 16:00:00
3_700_000_000 - 2087-04-01 01:46:40
3_800_000_000 - 2090-06-01 11:33:20
3_900_000_000 - 2093-08-01 21:20:00
4_000_000_000 - 2096-10-02 07:06:40
4_100_000_000 - 2099-12-03 16:53:20
- nvrspyx 6y agoTo add, Powershell: (Get-Date "1/1/1970").AddSeconds(1600000000).ToUniversalTime() or alternatively for your local time: (Get-Date "1/1/1970").AddSeconds(1600000000).ToLocalTime()
- netmare 6y agoHeh... I've run into this bug myself recently. Get-Date '...' returns a DateTime object of Unspecified kind, i.e. neither Local nor Utc. By design, such objects are interpreted as Local by ToUniversalTime() and as Utc by ToLocalTime(). They essentially assume the inverse of themselves, for better or worse. Since the Kind property is readonly, to get the real UTC date you need: $naive = (Get-Date "1/1/1970").AddSeconds(1600000000) $local = $naive.ToLocalTime() $utc = $local.ToUniversalTime()
- nvrspyx 6y agoInteresting. I'm using Powershell 7 (e.g. Powershell Core) and I'm not sure exactly which version number specifically, but the functions seem to work as intended on my Windows 10 machine.
- jasomill 6y agoOr, equivalently, $utc = [DateTimeOffset]::FromUnixTimeSeconds(16e8).UtcDateTime Incidentally, PS> ($utc, (Get-Date -AsUtc '1/1/1970'), (Get-Date -AsUtc), (Get-Date)).Kind Utc Utc Utc Local In your example, $naive.Kind -eq [DateTimeKind]::Unspecified correctly, because no DateTimeKind was specified. The peculiar behavior you observed with ToLocationTime and ToUniversalTime exists to avoid breaking changes in working[1] code written for versions of the .NET Framework before 2.0, where DateTime.Kind was introduced (as was DateTimeOffset, so ToLocationTime and ToUniversalTime should probably be deprecated). [1] "Breaking" changes exist for already-broken code, e.g., in Framework 2.0 and later, the return values of ToUniversalTime and ToLocalTime have Kinds Utc and Local, respectively, so applying the same conversion to an already-converted value no longer has any effect.
- LeoPanthera 6y agoOmit the "u" to see the result in local time, not UTC.
- themattmans 6y agoThank you both. I was looking for the right combination of flags and realized that the date(1) man page is far too dense for simple tasks like this. $ date -r 1600000000 Sun Sep 13 05:26:40 PDT 2020
- ericbarrett 6y agoThe datetime package is one of the best things about Python, and dare I say one of the best general purpose calendar modules ever written. It’s just so practical.
- BrandoElFollito 6y agoarrow (my favorite), pendulum or delorean are in my opinion much better (= easier to use, versatile, ...)
- sltkr 6y agoPython is great, but in this case, you could get almost identical output using bash alone: for t in {0..4100000000..100000000}; do TZ=UTC printf "%'13d - %(%Y-%m-%d %H:%M:%S)T\n" $t $t; done
- wwright 6y agoIt still can’t parse ISO8601 :(
- larkeith 6y ago`datetime.fromisoformat()`, as of 3.7 :D Though `dateutil` is still recommended for most cases.
- wwright 6y agoThat parses a subset and is only guaranteed to be compatible with Python’s “.toisoformat()”. (I imagine it would be backwards compatible to expand it to cover all of ISO8601 and I can’t tell why they haven’t.)
- londt8 6y agoISO8601 is quite large, they probably don't want to ship that big standard library modules which would parse 100% of ISO8601
- X6S1x6Okd1st 6y ago
- robk 6y agoIt made me feel better doing the math I'm likely to be alive for 3,000,000,000
- dylan604 6y ago> 4_100_000_000 - 2099-12-03 16:53:20 We're going to party like it's 2099! Watch out for that Y2K+100 bug!!
- leowoo91 6y agoI can already hear people from 2033 celebrating 2b..
- JdeBP 6y agoThat's the point that your library's time_t reaches those values. But the point at which you will be 1.6Gs since the Unix v4 Epoch is in fact 27 seconds earlier, because your time_t hasn't counted the leap seconds over that period. To do that with Unix tools, you need to work with TAI timekeeping, not UTC, and remember that the (biased) zero point for TAI timekeeping is 10s before the Unix v4 Epoch. % jot - 10 20 | while read -r d do printf "@40000000%08x%08x %s00Ms SI since the Unix v4 Epoch\n" \ "$d"00000010 0 "$d" done | TZ=right/UTC tai64nlocal 2001-09-09 01:46:18.000000000 1000Ms SI since the Unix v4 Epoch 2004-11-09 11:32:58.000000000 1100Ms SI since the Unix v4 Epoch 2008-01-10 21:19:37.000000000 1200Ms SI since the Unix v4 Epoch 2011-03-13 07:06:16.000000000 1300Ms SI since the Unix v4 Epoch 2014-05-13 16:52:55.000000000 1400Ms SI since the Unix v4 Epoch 2017-07-14 02:39:33.000000000 1500Ms SI since the Unix v4 Epoch 2020-09-13 12:26:13.000000000 1600Ms SI since the Unix v4 Epoch 2023-11-14 22:12:53.000000000 1700Ms SI since the Unix v4 Epoch 2027-01-15 07:59:33.000000000 1800Ms SI since the Unix v4 Epoch 2030-03-17 17:46:13.000000000 1900Ms SI since the Unix v4 Epoch 2033-05-18 03:32:53.000000000 2000Ms SI since the Unix v4 Epoch % Also, your figures for 0.0Gs and 0.1Gs are nonsense anyway. Unix didn't adopt this Epoch and method of timekeeping until 4th Edition, somewhere in 1974 according to Unix historians. Yes, it's tricky to pin down the exact date of adoption. The Epoch was changed every year before then, as earlier versions of Unix measured time in 60ths of a second since the start of the year. This has made reconstructing Unix history from tape archives non-trivial. If you want to count seconds since the start of the first Unix Epoch, in 1st Edition, you have to count from the start of 1971. And no, that's not the same as how old Unix is. (And yes, those values for 2023 onwards are somewhat speculative, as there will no doubt be more leap seconds.)