Do you need to access the exact date & time from your CMS datetime field, to use in javascript, an integration or JSON-LD?
Here's how to get it.
When you insert a datetime field into an HTML Embed, it's emitted in an incomplete form;
Unfortunately, this doesn't contain the information you need and it's not in a format that you can use with most systems.
APIs typically require an ISO-8601 datetime format, which looks more like this-
2024-04-01T23:03:04+13:00
This format unambiguously indicates April 1st, 2024, at 11:03 pm and 4 seconds, in the GMT+13 timezone.
You can solve this, with a bit of a hack;
Webflow.js uses Moment.js under the hood for its date functions, and this includes the format strings that you see inside of the CMS field embeds.
Adding the Z at the end ensures that the stored timezone is actually represented, e.g. +13:00.
NOTE: Webflow appears to store datetime fields internally in a consistent and unambiguous form. When you render it using the Z timezone specifier above, the datetime will automatically adjust to the timezone that your site is set to in site settings, and will specify that timezone offset, e.g. -04:00.
This is ideal for your scripts and API use, since it expresses a complete and unambiguous time - however using the Z specifier is essential to get that timezone setting automatically. The reason is that Webflow is pre-converting the datetimes to your site's timezone setting prior to the formatting step. If you instead used e.g. +00:00 in the format string, you would get an incorrect datetime, unless your site settings are also set to a +00:00 timezone like [GMT+0:00] Europe/London.
For display purposes, you create custom displays using multiple date time parts;