DevFlow

DevOverflow

Search
Menu
DevFlow

DevOverflow

Home menu icon

Home

Community menu icon

Community

Collections menu icon

Collections

Find Jobs menu icon

Find Jobs

Tags menu icon

Tags

Ask a question menu icon

Ask a question

    Menu

    Top Questions

    How to center a div?

    chevron

    How to do code parsing with React.js and NextJS?

    chevron

    How to get better at Nextjs?

    chevron

    Postgres: upgrade a user to be a superuser? ?

    chevron

    This is another test question

    chevron

    Popular Tags

    nextjs

    6

    React

    4

    next.js

    3

    reactjs

    3

    css

    3

    Profile

    Juan Cruz Cáceres

    upvote

    0

    downvote

    0

    star

    In JavaScript, how to create a date when given an OLE date format and keep it in GMT/UTC and NOT a local time zone using kendo?

    clock icon

    Asked 9 months ago

    message

    0 Answers

    eye

    1 Views

    0

    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; 
    }
    Expand snippet

     

    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?

    javascript
    jquery

    Write your answer here

    0 Answers