I am struggling with keeping a date given to me in OLE date format, like what an Excel spreadsheet gives you for the value (i.e. it's a float value like: 40967.6424503935). Ok I get how to convert the date to a JavaScript date, but I have to keep it in GMT if the timezone is NOT specified. The Date() constructor is converting it to a local time, so when I finally convert it to the format I want it comes up in CST of course.
function excelOleDateToJavaScriptString(excelDateValue, format) {
// Convert to a JavaScript Date object
const jsDate = new Date((excelDateValue - 25569) * 86400 * 1000);
var formattedDate = kendo.toString(jsDate, format); // given a format like mm-dd-yy
// it converts to local time.
return formattedDate;
}
I want to maintain the given date, and not my current timezone of CST.
If I give a date in OLE of like 01-01-24, it gets converted to 12-31-23 which is CST, the time zone I am in, great... I get that the JavaScript Date() constructor compensates for the current time zone and therefore sets it back to my current time zone.
Also, the format which is a string value can be ANY format that Excel deems as valid. I do not know ahead of time what that format string will be...and the requirement is to keep it in the format the user selects...we cannot convert it. So, no I cannot use the tried and true: toUTCString() or toISOString().
Any suggestions?