Conversion of date time GMT to a local time zone
I have used the below script to convert a date time field to local time zone. But, it is not giving the expected result when I use it in Adobe Livecycle Designer.
var gmtDateString = "2024-01-16T18:24:56";
// Parse the GMT date string
var gmtDate = Date(gmtDateString);
// Get the local timezone offset
var localTimeZoneOffset = Date("1900-01-01T00:00:00") - Date("1900-01-01T00:00:00UTC");
// Adjust the date by adding the local timezone offset
gmtDate = DateAdd(gmtDate, 0, 0, 0, 0, localTimeZoneOffset, 0);
// Manually construct the adjusted date string for the local timezone
var localDateString = gmtDate.getFullYear() & "-" &
padZero(gmtDate.getMonth() + 1) & "-" &
padZero(gmtDate.getDate()) & "T" &
padZero(gmtDate.getHours()) & ":" &
padZero(gmtDate.getMinutes()) & ":" &
padZero(gmtDate.getSeconds());
// Function to pad single-digit values with zero
function padZero(value) {
return value < 10 ? '0' + value : value;
}
this.rawValue = localDateString;
It is giving only the correct time, but the date is coming wrong as 15th August 1924. Could anyone please help and guide here.