Converting Google spreadsheet date into a JS Date object?

前端 未结 7 980
半阙折子戏
半阙折子戏 2020-12-01 12:49

I\'ve been going round in circles on this one... I\'ve got a spreadsheet which holds two dates, and I need to find the number of elapsed years between the two (ie. someone\'

7条回答
  •  旧巷少年郎
    2020-12-01 13:50

    By "serial number" I'm guessing you're talking about a unix time in seconds or milliseconds from the epoch. You can simply use the standard Javascript Date object:

    new Date(value);
    

    Google is your friend from there. Here's some references to start you off:

    • W3 Schools reference
    • W3 Schools tutorial
    • MDN reference

    Javascript allows you to do simple subtraction with two Dates, returning you the time difference in ms.

    var timeDiffInMS = date2 - date1;
    

    That should be all you need to figure it out, so I'll leave the years calculation as an exercise for the reader.

提交回复
热议问题