Trupti
Trupti

Reputation: 973

Google sheet: Get the date in correct format

I am having one google sheet which contains date. While fetching it, it shows 7/4/2018 as 43285 in javascript.

I want to show date as it is. How can I do it?

Thank you, Trupti

Upvotes: 1

Views: 67

Answers (1)

ReyAnthonyRenacia
ReyAnthonyRenacia

Reputation: 17613

Use the javascript Date Object to work with time then use the snippets from this SO post

function convertEpochToSpecificTimezone(offset){
    var d = new Date(1495159447834);
    var utc = d.getTime() + (d.getTimezoneOffset() * 60000);  //This converts to UTC 00:00
    var nd = new Date(utc + (3600000*offset));
    return nd.toLocaleString();
}

and this SO post as code reference.

var now = new Date(); 
var now_utc =  Date.UTC(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate(),
 date.getUTCHours(), date.getUTCMinutes(), date.getUTCSeconds());

 return new Date(now_utc);

Upvotes: 1

Related Questions