/*
const date = new Date();
function getDateTimeRange(date: Date, timezone = "Europe/Stockholm") {
const tzDate = new Date(date.toLocaleString("en-US", { timeZone: timezone }));
console.log(tzDate.toUTCString());
const start = new Date(tzDate);
start.setHours(0, 0, 0, 0);
const end = new Date(tzDate);
end.setHours(23, 59, 59, 999);
return { start, end };
}
*/
// Get current local date and time
const currentDate = new Date();
const currentDate = new Date("2023-10-05T23:30:00.000Z");
// Calculate yesterday's date
const yesterdayDate = new Date(currentDate);
yesterdayDate.setDate(currentDate.getDate() - 1);
// Set the time range for yesterday (start and end) in local time
const yesterdayStart = new Date(yesterdayDate.getFullYear(), yesterdayDate.getMonth(), yesterdayDate.getDate(), 0, 0, 0, 0);
const yesterdayEnd = new Date(yesterdayDate.getFullYear(), yesterdayDate.getMonth(), yesterdayDate.getDate(), 23, 59, 59, 999);
// Convert the local time to UTC
const yesterdayStartUTC = yesterdayStart.toISOString();
const yesterdayEndUTC = yesterdayEnd.toISOString();
// Display the time range in UTC
console.log(yesterdayStartUTC); // Start time in UTC
console.log(yesterdayEndUTC); // End time in UTC
console.log(Intl.DateTimeFormat().resolvedOptions().timeZone)
var offset = new Date().getTimezoneOffset();
console.log(offset);
// getDateTimeRange(date);
//console.log(getDateTimeRange(date).start.toISOString());
// console.log(getDateTimeRange(date).end.toISOString());
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.