A simple way to manipulate, compare, and format dates and times across the Earth
- Get/set dates and times in remote timezones
- Global support for Daylight Savings Time, leap years + seconds, and hemispheres
- Orient by quarter, season, month, and week
- Remote date comparison
- Written in ES2015 JS, published as ES5, tested for Node and the browser
- Weighs in at just 35KB (12KB compressed)
- Heavily tested, Apache 2.0 licensed
- Made by your friends at Begin
Install
npm install spacetime --save
var spacetime=require('spacetime')
s = spacetime(1489520157)
s = spacetime([2017, 5, 2])
s = spacetime('July 2, 2017 5:01:00')
s = spacetime(1489520157, 'Canada/Pacific')
s = spacetime('2019/05/15', 'Canada/Pacific')
s = spacetime.now()
s = spacetime.today()
s = spacetime.tomorrow()
Get & Set date info
s.date()
s.year()
s.season()
s.hour(5)
s.date(15)
s.day('monday')
s.month('march')
s.quarter(2)
s.progress().month = 0.23
s.progress().day = 0.48
s.progress().hour = 0.99
s.add(1, 'week')
s.add(3, 'quarters')
s.subtract(2, 'months').add(1,'day')
s.startOf('day')
s.startOf('month')
s.endOf('quarter')
s.clone()
s.isValid()
Comparison between Dates
let d = spacetime([2017, 5, 2])
let start = s.clone()
let end = s.clone()
start.subtract(1, 'milliseconds')
end.add(1, 'milliseconds')
s.isAfter(d)
s.isEqual(d)
s.isBefore(d)
s.isBetween(start, end)
s.isSame(d, 'year')
s.isSame(d, 'date')
s.diff(d, 'day')
s.diff(d, 'month')
Timezone info
s.goto('Australia/Brisbane')
spacetime.whereIts('8:30pm','9:30pm')
spacetime.whereIts('9am')
s.timezone().name
s.timezone().hemisphere
s.timezone().current.offset
s.timezone().current.isDst
s.format('time')
s.format('numeric-uk')
s.format('month')
s.format('month-short')
MIT