1

I'm using javascript only (not allowed to use any 3rd party js), and i want to retrieve current datetime in UTC+7 with a format like this yyyy-MM-ddTHH:mm:ss.SSSTZD for example:

2019-05-14T16:36:20.000+07:00
blue
  • 1,695
  • 3
  • 10
  • 17

2 Answers2

1

If you use momentjs you can accomplish that like so:

console.log(moment().utcOffset(7).format("YYYY-MM-DDTHH:mm:ss.SSSZ"))
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.24.0/moment.min.js"></script>
Slawomir Chodnicki
  • 1,525
  • 11
  • 16
0
enter code here

let date = new Date(); 

console.log('UTC' + (-date.getTimezoneOffset() < 0 ? '-' : '+') + (Math.abs(date.getTimezoneOffset() / 60) < 10 ? '0' : '') + (Math.abs(date.getTimezoneOffset() / 60)) + ':00');
  • See this post to complete this answer with UTC : https://stackoverflow.com/questions/55903592/how-to-get-client-timezone-in-utc-format-like-utc0500-in-php-or-javascript/55905225#55905225 – PopHip May 14 '19 at 10:01