React Native
React Native
How to Parse a TimeStamp (such as 2016-11-11T14:32:17.0908971Z)
Timestamps are frequently used in REST API responses. This example demonstrates how to parse a timestamp string to get at the date/time components in the local timezone or in the GMT/UTC timezone.Chilkat React Native Downloads
import { CkDateTime, DtObj } from '@chilkat/react-native'
function chilkatExample() {
// Let's say we have a timestamp string such as 2016-11-11T14:32:17.0908971Z
const strTimestamp = '2016-11-11T14:32:17.0908971Z';
const dateTime = new CkDateTime();
dateTime.setFromTimestamp(strTimestamp);
// Get a DtObj in the local timezone.
let bLocalTimezone = true;
const dt = new DtObj();
dateTime.toDtObj(bLocalTimezone, dt);
// Get the individual date/time components
console.log('-- Local Time --');
console.log(`Year: ${dt.year}`);
console.log(`Month: ${dt.month}`);
console.log(`Day: ${dt.day}`);
console.log(`Hour: ${dt.hour}`);
console.log(`Minutes: ${dt.minute}`);
console.log(`Seconds: ${dt.second}`);
// Get a DtObj in the GMT/UTC timezone.
bLocalTimezone = false;
dateTime.toDtObj(bLocalTimezone, dt);
// Get the individual date/time components
console.log('-- UTC Time --');
console.log(`Year: ${dt.year}`);
console.log(`Month: ${dt.month}`);
console.log(`Day: ${dt.day}`);
console.log(`Hour: ${dt.hour}`);
console.log(`Minutes: ${dt.minute}`);
console.log(`Seconds: ${dt.second}`);
}