0

I'm converting the utc from the server to local time using javascript and it works.But I need only the time rather than the date+time.Without using moment. server time(UTC format) : "2018-02-03T10:00:00" converted local time :2018-02-03T04:30:00.000Z In the above local time I need only "04:30" alone .Is there any way to get it?

I tried the below one to convert from utc to local time

new Date(response.data.maxDate).toISOString();
Hema Nandagopal
  • 668
  • 12
  • 35

1 Answers1

0

console.log(new Date().toLocaleTimeString());

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleTimeString

Date.prototype.toLocaleTimeString() Returns a string with a locality sensitive representation of the time portion of this date based on system settings.

var time = datetime.toLocaleTimeString();

And if you want only hours:minutes then you can do this

date=new Date();
date.getHours() +':'+ date.getMinutes()

    date=new Date();
    console.log(date.getHours()+':'+date.getMinutes());
yajiv
  • 2,901
  • 2
  • 15
  • 25
  • It would better to reference the [*method page*](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleTimeString), which has a better summary of the behaviour: "*The toLocaleTimeString() method returns a string with a language sensitive representation of the time portion of this date.*" – RobG Mar 09 '18 at 08:54