Timestamps
Timestamps are a critical part of Timekit.
All timestamps in Timekit are ISO 8601 formatted, with a date, a time to the second and a UTC offset: YYYY-MM-DDTHH:MM:SS+HHMM.
Input: the API accepts timestamps with an offset written as +0100, +01:00 or Z, so RFC 3339 / ATOM timestamps such as 2019-11-24T08:46:01+01:00 work. The offset is required and fractional seconds are not allowed: 2019-11-24T08:46:01 (no offset) and 2019-11-24T08:46:01.123Z (milliseconds) are both rejected with a 422.
Output: timestamps in responses use an offset without a colon, e.g. 2019-11-24T08:46:01+0000. Make sure your parser accepts this format: some strict RFC 3339 parsers require the colon.
Example:
2019-11-24T08:46:01+0000
Below are examples of how you generate an accepted timestamp string:
javascript// Built-in with output in Zulu/UTC timezone:
// e.g. 2019-11-24T08:46:01Z
const date = new Date();
const isoDate = date.toISOString().split('.')[0]+'Z';
// Using moment.js with timezone offset:
// e.g. 2019-11-24T08:46:01+01:00
const moment = require('moment');
const date = new Date();
const isoDateOffset = moment(date).format();
rubyrequire 'time'
now = Time.now
isoDate = now.rfc3339
php$now = new DateTime();
$isoDate = $now->format(DateTime::RFC3339);
java// e.g. 2019-11-24T08:46:01+01:00 (truncated to whole seconds)
String isoDate = ZonedDateTime.now()
.truncatedTo(ChronoUnit.SECONDS)
.format(DateTimeFormatter.ISO_OFFSET_DATE_TIME);
csharpDateTime localTime = DateTime.Now;
DateTimeOffset localTimeWithOffset = new DateTimeOffset(localTime, TimeZoneInfo.Local.GetUtcOffset(localTime));
String isoDate = localTimeWithOffset.ToString("yyyy-MM-ddTHH:mm:ssK")
objectivecNSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
NSLocale *enUSPOSIXLocale = [NSLocale localeWithLocaleIdentifier:@"en_US_POSIX"];
[dateFormatter setLocale:enUSPOSIXLocale];
[dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssZZZZZ"];
NSDate *now = [NSDate date];
NSString *isoDate = [dateFormatter stringFromDate:now];
swiftlet dateFormatter = DateFormatter()
let enUSPosixLocale = Locale(identifier: "en_US_POSIX")
dateFormatter.locale = enUSPosixLocale
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZZZZZ"
let isoDate = dateFormatter.string(from: Date())
pythonimport datetime
# e.g. 2019-11-24T08:46:01+01:00 (local time with offset, no microseconds)
isoDate = datetime.datetime.now().astimezone().replace(microsecond=0).isoformat()
gonow := time.Now()
isoDate := now.Format(time.RFC3339)