Hello fellas,
I tried to use Intl.DateTimeFormat
, but it isn’t available. What’s the alternative?
Thanks in advance,
Hello fellas,
I tried to use Intl.DateTimeFormat
, but it isn’t available. What’s the alternative?
Thanks in advance,
Could you please explain what you are trying to achieve? It’s likely that this can be accomplished using operators
Sure. I need to:
JSDOM
.internalDate
) from unix epoch (UTC) to a human readable date localized in Mexico City.Steps 1 to 3 are already covereted. I’m working in step 4.
Regards,
Alfredo
Just figured it out how to do it. Here is the code for future references:
const internal_date = new Date(parseInt(data["{{8.`value`.`internalDate`}}"]));
const mx_date = internal_date.toLocaleString('es-MX', { timeZone: 'America/Mexico_City' });
Regards,
I’ve been using Intl.DateTimeFormat without problem in JavaScript nodes. Here’s a snippet
// Use the timestamp_override if it is not empty, otherwise use the current timestamp
const currentTimestamp = timestampOverride && timestampOverride !== "null" ? new Date(parseInt(timestampOverride,10)).getTime() : Date.now();
//console.log(currentTimestamp);
// Subtract 24 hours in milliseconds
const timestamp24HoursAgo = currentTimestamp - 24 * 60 * 60 * 1000;
//console.log(timestamp24HoursAgo);
// Format the date of the previous day as "mm/dd/YYYY"
const previousDate = new Date(timestamp24HoursAgo);
//console.log(previousDate);
const formattedPreviousDate = `${String(previousDate.getMonth() + 1).padStart(2, '0')}/${String(previousDate.getDate()).padStart(2, '0')}/${previousDate.getFullYear()}`;
//console.log(formattedPreviousDate);
// Create a timezone-aware formatted date for central Time Zone
const centralTimeFormatter = new Intl.DateTimeFormat('en-US', {
timeZone: 'America/Chicago',
year: 'numeric',
month: '2-digit',
day: '2-digit'
});
const centralTimeFormattedPreviousDate = centralTimeFormatter.format(previousDate);
You are right Intl.DateTimeFormat
is indeed available. I must have misread one of the errors shown in the console.