2
Thu Apr 06 2018 09:24:00 GMT+0530 (India Standard Time) 

I want to get this date in ISO format.(Not just in IST timezone, but other timezones as well). If I use .toISOString() method of Date it converts the date to UTC. I want to get the date in ISO format but retain the date in the given timezone. How can I do that?

1
  • 1
    Use .format from moment. d = moment(); d.format(); Commented Apr 5, 2018 at 6:06

1 Answer 1

2

Check below snippet to convet into different timezone

and refer to get date in ISO format Refer this Link

function toTimeZone(time, zone) { var format = 'YYYY/MM/DD HH:mm:ss ZZ'; return moment(time, format).tz(zone).format(format); } //Current Date var CurrentDate = moment().toISOString(); console.log(CurrentDate); /*var date = '2018/03/23 05:00:00 +0000';*/ var timezone = Intl.DateTimeFormat().resolvedOptions().timeZone; //Current Date in server timezone var result = toTimeZone(CurrentDate, timezone); console.log(Intl.DateTimeFormat().resolvedOptions().timeZone); console.log(result); var result = toTimeZone(result, 'America/Los_Angeles'); console.log('America/Los_Angeles'); console.log(result);
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.21.0/moment.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/moment-timezone/0.5.14/moment-timezone-with-data.min.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.