0

I'm still learning javascript, so I don't understand how to convert the epoch time to the standard time format using GMT+7, the time zone where I currently reside.

How do I change it to the desired timezone?

I have my source code here:

// convert time to human-readable format YYYY/MM/DD HH:MM:SS
  function epochToDateTime(epochTime){
    var epochDate = new Date(epochToJsDate(epochTime));
    var dateTime = epochDate.getFullYear() + "/" +
      ("00" + (epochDate.getMonth() + 1)).slice(-2) + "/" +
      ("00" + epochDate.getDate()).slice(-2) + " " +
      ("00" + epochDate.getHours()).slice(-2) + ":" +
      ("00" + epochDate.getMinutes()).slice(-2) + ":" +
      ("00" + epochDate.getSeconds()).slice(-2);
  
    return dateTime;
  }
Ethan
  • 881
  • 8
  • 14
  • 26
  • Does this answer your question? https://stackoverflow.com/a/64089049/2358409 – uminder Jul 31 '22 at 09:50
  • JS dates don't have a concept of configurable time zones: they're always in the time zone of the host operating system. Dates can be formatted as strings in the system time zone or UTC. You can explore the various date methods here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date – jsejcksn Jul 31 '22 at 09:54

1 Answers1

0

Is this what you need?

const now = new Date(Date.now())
const dd = now.getDate()
const mm = now.getMonth()
const yyyy = now.getFullYear()
const HH = now.getHours()
const MM = now.getMinutes()
const SS = now.getSeconds()

console.log(yyyy + '/' + mm + '/' + dd + ' ' + HH + ':' + MM + ':' + SS)
rustyBucketBay
  • 4,320
  • 3
  • 17
  • 47