logoalt Hacker News

freeopinionyesterday at 4:32 PM3 repliesview on HN

prompt> use javascript to convert a unix timestamp to a date in 'YYYY-MM-DD' format using Temporal

answer> Temporal.Instant.fromEpochSeconds(timestamp).toPlainDate()

Trust but verify?


Replies

meindnochyesterday at 8:22 PM

  >Temporal.Instant.fromEpochSeconds(0).toPlainDate()
  Uncaught TypeError: Temporal.Instant.fromEpochSeconds is not a function
Hmm, docs [1] say it should be fromEpochMilliseconds(0). Let's try with that!

  Temporal.Instant.fromEpochMilliseconds(0).toPlainDate()
  Uncaught TypeError: Temporal.Instant.fromEpochMilliseconds(...).toPlainDate is not a function
[1] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
show 1 reply
nielsbotyesterday at 4:51 PM

what does this mean in this convo?

show 2 replies
eszedyesterday at 4:51 PM

I mean... Yes? That looks correct to me°, but it's been a minute since I worked with Temporal, so I'd run it myself and examine the output before I cut and paste.

Or have I missed your point?

---

°Missing a TZ assertion, but I don't remember what happens by default. Zulu time? I'd hope so, but that reinforces my point.

show 1 reply