on the Airtable community forums that he wanted to include a nicely formatted date in a weekly email. Although he could get the expected trigger time for the automation, the result was an ugly ISO string.
Discussion
To get the current date and time in JavaScript, create a new date object.
const now = new Date()
However this date object will not be formatted for humans to read.
Fortunately, you can format date objects for human consumption with toLocaleString().
In order to format the timestamp, you need to specify several options
date style. If you want to include the date, you can choose from the full, long, medium, or short format.
time style. If you want to include the time, you can choose from the full, long, medium, or short format.
These options will give a short date and time in New York timezone, such as 4/26/23, 6:53 PM.
const options = {
timeZone: "America/New_York",
dateStyle: "short",
timeStyle: "short",
}
If you want only the date without the time, leave out the timeStyle.
const options = {
timeZone: "America/New_York",
dateStyle: "short",
}
You also need the locale. The locale indicates the order of elements in the date (MM/DD/YYYY versus DD/MM/YYYY) and the language. I usually use en-us because I am located in the United States. If you are located elsewhere, you can see a list of locales