Many methods accept an optional timezone parameter. Use 'UTC' for UTC operations:
const time = HolyTime.now();// Get values in UTCconst utcHour = time.get('hour', 'UTC');const utcDay = time.get('day', 'UTC');// Format in UTCtime.format('YYYY-MM-DD HH:mm:ss', 'UTC');// '2024-03-04 19:30:45'// Start of day in UTCconst utcDayStart = time.startOf('day', 'UTC');
const time = new HolyTime(new Date('2024-03-04T14:30:00'));// Local time (depends on system timezone)time.format('YYYY-MM-DD HH:mm:ss');// '2024-03-04 14:30:00' (if system is in that timezone)// UTC timetime.format('YYYY-MM-DD HH:mm:ss', 'UTC');// '2024-03-04 19:30:00' (if local timezone is EST, UTC-5)
const time = HolyTime.now();// Same moment in different timezonestime.format('YYYY-MM-DD HH:mm:ss', 'America/New_York');// '2024-03-04 14:30:00'time.format('YYYY-MM-DD HH:mm:ss', 'Europe/London');// '2024-03-04 19:30:00'time.format('YYYY-MM-DD HH:mm:ss', 'Asia/Tokyo');// '2024-03-05 04:30:00'
Gets a time component value in the specified timezone.
const time = new HolyTime(new Date('2024-03-04T23:30:00Z'));// Hour in different timezonestime.get('hour', 'UTC'); // 23time.get('hour', 'America/New_York'); // 18 (UTC-5)time.get('hour', 'Asia/Tokyo'); // 8 (next day, UTC+9)// Day can change across timezonestime.get('day', 'UTC'); // 4time.get('day', 'Asia/Tokyo'); // 5
Returns the end of the interval in the specified timezone.
const time = new HolyTime(new Date('2024-03-04T14:30:00'));// Start of day in different timezonestime.startOf('day', 'UTC');time.startOf('day', 'America/New_York');time.startOf('day', 'Asia/Tokyo');// End of month in specific timezonetime.endOf('month', 'Europe/Paris');
// Start of day in New Yorkconst nyDayStart = HolyTime.startOf( 'day', new Date('2024-03-04T14:30:00'), 'America/New_York');// End of week in Tokyoconst tokyoWeekEnd = HolyTime.endOf( 'week', new Date(), 'Asia/Tokyo');
The startOf() and endOf() methods with timezone support are at src/time.ts:218-289 and src/time.ts:295-359.
// Get the start of tomorrow in Tokyo timeconst tokyoTomorrow = HolyTime.next('day', new Date(), 'Asia/Tokyo');// Format it in multiple timezonesconsole.log('Tokyo:', tokyoTomorrow.format('YYYY-MM-DD HH:mm', 'Asia/Tokyo'));console.log('UTC:', tokyoTomorrow.format('YYYY-MM-DD HH:mm', 'UTC'));
When working with timezones, be aware of daylight saving time (DST) transitions. The library handles these automatically using the browser’s Intl API.
// Store as UTC timestampconst timestamp = HolyTime.now().getTime();// Display in user's timezoneconst userTz = HolyTime.getTimeZone();const displayTime = new HolyTime(timestamp).format('YYYY-MM-DD HH:mm', userTz);