Skip to content

fromFormat and unix epoch #1757

@nlooije

Description

@nlooije

Describe the bug
I cannot use the token 'x' and 'X' to convert a unix epoch time in (milli)seconds to a datetime using the .fromFormat() method.

To Reproduce
luxon.DateTime.fromFormat('1769758221', 'X')

Actual vs Expected behavior
fromFormat() method gives a unparseable error with explanation the input "1769758221" can't be parsed as format X .
I expect the result to be datetime object which when converted toISO() is 2026-01-30T08:30:21.000+01:00

Desktop:

  • OS: Windows 11
  • Browser Chrome 144.0.7559.97
  • Luxon version 3.7.2
  • Europe/Amsterdam

Additional context
I may be misunderstanding if fromFormat() method can convert from unix epoch timestamps at all. It is not clear from the documentation. There is a macro token 'x' and 'X' but it seems to work for the toFormat() method instead.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions