0
var aestTime = new Date().toLocaleString("en-US", {timeZone: "Australia/Brisbane"});
aestTime = new Date(aestTime);
console.log('AEST time: '+aestTime.toLocaleString())

var asiaTime = new Date().toLocaleString("en-US", {timeZone: "Asia/Shanghai"});
asiaTime = new Date(asiaTime);
console.log('Asia time: '+asiaTime.toLocaleString())

var usaTime = new Date().toLocaleString("en-US", {timeZone: "America/New_York"});
 usaTime = new Date(usaTime);
 console.log('USA time: '+usaTime.toLocaleString())

This is the output from running the above code:

AEST time: 11/12/2019, 3:39:31 PM
test.html:36 Asia time: 11/12/2019, 1:39:31 PM
test.html:40 USA time: 11/12/2019, 12:39:31 AM 

Without giving timezone I want the receive the same output, how do I do that?

var aestTime =  

output :- 11/12/2019 3:39:31 PM  

var asiaTime =

 output:- 11/12/2019, 1:39:31 PM 

var usaTime = 

 11/12/2019, 12:39:31 AM
A Friend
  • 1,420
  • 17
  • 22
atchuth
  • 1
  • 2
  • Check this https://stackoverflow.com/questions/6525538/convert-utc-date-time-to-local-date-time and https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleString – Jayakumar Thangavel Nov 12 '19 at 06:55
  • how to get a DateTime based on country Without mentioning timezone? – Jayakumar Thangavel Nov 12 '19 at 06:57
  • getting date in this format 2018-10-10 15:54:29. even i too don't know that's why i had posted..but my requirement should be without mentioning timezone we should get current local system time – atchuth Nov 12 '19 at 06:59

2 Answers2

0

You can try momentjs. Refer to https://momentjs.com/docs/

The code can be

const moment = require('moment');
const now = moment();
console.log(now.format('L LTS'));

This will give the current local system time without mentioning the timezone.

The result will be

11/12/2019 12:49:46 PM

Abhishek
  • 1
  • 1
  • 4
  • i have time in this format "2019-11-12 05:59:27" this time should be converted to local system user may be from Usa or England or any country but that time should be converted to user local system time – atchuth Nov 12 '19 at 08:39
0

let utcTime = "2019-12-27 20:30:00"; let local = moment.utc(utcTime,'YYYY-MM-DD HH:mm:ss A').local().format("YYYY-MM-DD hh:mm:ss A");

output:-

2019-12-28 02:00:00 AM

atchuth
  • 1
  • 2