I'm trying to create two variables in d3, one that is the current hour & minute (in 00:00 format) and one that is simply the current time with the hour value subtracted by two. So, for instance: current time is 15:38, the other variable would be calculated to be 13:38.
Here's my current code for getting the current time (in coffeescript):
formatTime = d3.time.format("%H:%M")
currentTime = (d) -> formatTime(new Date())
Thanks in advance!
Checkout d3.time.interval:
> d = new Date()
Fri Sep 13 2013 00:00:00 GMT-0400 (Eastern Daylight Time)
> twoHoursAgo = d3.time.hour.offset(d, -2)
Fri Sep 13 2013 17:09:04 GMT-0400 (Eastern Daylight Time)
> [twoHoursAgo, d].map(formatTime)
["17:09", "19:09"]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With