A lightweight way to manipulate, traverse, compare, and format dates and times across planet Earth
Spacetime does some ugly things. it can sometimes get confused. but by making realistic compromises space-time considerably under-weighs most date libraries.
It lets you have a mostly-great time, without thinking about awful things.
- Get/set dates and times in remote timezone
- 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)
- Well tested, Apache 2.0 licensed
- Made by your friendly friends at Begin
Installation
<script src="https://unpkg.com/spacetime"></script>
<script>
var d = spacetime('March 1 2012', 'America/New_York')
//set the time
d = d.time('4:20pm')
d = d.goto('America/Los_Angeles')
d.time()
//'1:20pm'
</script>
npm install spacetime
const spacetime = require('spacetime')
let d = spacetime.now('Europe/Paris')
d.dayName()
//'Wednesday'
d.isAsleep()
//true
Or with Typescript
import spacetime from 'spacetime'
let d = spacetime.now()
d.format('nice')
//'Apr 1st, 4:32pm'
make sure to add this to your tsconfig.json
:
{
"compilerOptions": {
"esModuleInterop": true
}
}
changelog
v6.6.2
[fix] for formatting when the output is 0 ????
[fix] for leap-day in .date() method
update deps
add github release/publish script
v5.9.0
add support for changing start/end of the week
allow more flexible .i18n() inputs
v5.8.0
faster diff for large-number of months
more support for esoteric iso formats
add format('iso-month')
change fallback behaviour for set failure edge-cases
v5.7.0
avoid setting dates/months/hours past maximums and minimums
.hour(24) now changes date to tomorrow
faster diffs for large (decade-long) ranges
[big] fix awkward diff/since issues ('dec 25->jan 5' should be 0 years)
v5.6.0
support typescript types by Jacob Craig
use given timezone when given a spacetime object as an input
adds .every(unit, to) method
set UTC as default fallback timezone
V5.4.0
support more time input formats
fixes offset input issue #103
V5.3.0
added more iana timezones
fixed zero-padding in iso offsets
support half hour offsets in iso formats
Gridster.js: A jQuery Plugin for Building Intuitive Draggable Layouts