Skip to content

Latest commit

 

History

History
22 lines (14 loc) · 532 Bytes

React.luxon.md

File metadata and controls

22 lines (14 loc) · 532 Bytes

Use luxon in React

$ npm install luxon

Example: difference of expired_at and now

import {DateTime, Settings} from "luxon";

Settings.defaultZoneName = "UTC";  // Set default timezone as "UTC"

const expired_at = DateTime.fromISO("2021-10-31T18:31:17");
const now = DateTime.utc();

const diff = DateTime.fromISO(expired_at).diff(now, ["days", "hours", "minutes"])

console.log(`days: ${diff.days} hours: ${diff.hours} minutes: ${diff.minutes}`)

luxon docs: https://moment.github.io/luxon/#/tour