DateTime,fromMillis(1) returns 1970-01-01 and 1 milliseconds, but DateTime,fromMillis(0) returns the current time. Is this a bug or does it have a reason ?
Sounds like a bug; I bet it's 0 being falsy causing a problem.
Fixed in 8e20a4e, will release soon.
Released in 0.2.7
Tested in 0.2.8
.. still broken (when running the example code below)
var luxon = require("luxon")
luxon.DateTime
.fromMillis(0)
.setZone('America/Los_Angeles');
because of this line
https://github.com/moment/luxon/blob/master/src/datetime.js#L331
Hmm, yeah, i'll clean that up
Fixed in c7a76ce4, released in 0.2.9
Looks like this is back in 0.5.8
import { DateTime } from 'luxon';
const date = DateTime.fromMillis(1521250121);
console.log('DateTime', date); // DateTime 1970-01-18T08:34:10.121-06:00
@paddingtonsbear I don't think you saved the codesandobx example; I just see the boilerplate at that link. But I looked at the example you pasted in and that looks fine. What did you expect the result of that to be?
I believe I might be using the package incorrectly, I was trying to format the unix time 1521250121 to yyyy/mm/dd but the fromMillis function keeps returning 1970-01-18 and not the correct date which is suppose to be 2018-03-17.
Actually the codesandbox is saved, I am currently logging the responses to console, I should have included that in my initial post. Click on src/index.js and you should find my example
Unix timestamps are in seconds, not milliseconds. Try this:
DateTime.fromMillis(1521250121 * 1000).toFormat("yyyy/MM/dd") //=> "2018/03/16"
(that might be the 17th in your zone)
Of cos it is 馃槥 , thanks @icambron 馃憤
Most helpful comment
Unix timestamps are in seconds, not milliseconds. Try this:
(that might be the 17th in your zone)