-2

I want to get only time from 1970-01-01T09:30:00.000Z. Like 9.30 or 16:00. How to do this?

phuzi
  • 9,921
  • 3
  • 25
  • 45
ananya
  • 911
  • 6
  • 29
  • 49
  • `'1970-01-01T09:30:00.000Z'.split('T')[1].split(':').slice(0,2).join(':')` – Jaromanda X Apr 25 '19 at 10:10
  • 1
    Possible duplicate of [Where can I find documentation on formatting a date in JavaScript?](https://stackoverflow.com/questions/1056728/where-can-i-find-documentation-on-formatting-a-date-in-javascript) – Boaz Apr 25 '19 at 10:19

5 Answers5

1

You can use JavaScript's Date class. Here a short Example:

const d = new Date('1970-01-01T09:30:00.000Z') // Parses a ISO 8601 Date
console.log(d.getHours()); // gets the hours in the timezone of the browser.
console.log(d.getUTCHours()); // gets the hours in UTC timezone.
console.log(d.getMinutes()); // gets the minutes in the timezone of the browser.
console.log(d.getUTCMinutes()); // gets the minutes in UTC timezone.
console.log(d.getHours() + ':' + d.getMinutes());
console.log(d.getUTCHours() + ':' + d.getUTCMinutes());
Rain336
  • 1,312
  • 11
  • 17
0

I hope this will help anyone in future. I think u can use Date pipe in angular like below

{{ 2019-06-26T19:31:00.000Z | date:"dd/MM/yyyy HH:mm:ss"}}

It will give following o/p 27/06/2019 01:01:00

For Only time use following

{{ 2019-06-26T19:31:00.000Z | date:"HH:mm"}}

It will give following o/p 01:01

sangRam
  • 161
  • 3
  • 14
-1

MomentJS is a great time management library for JS projects, Check it out !

aelagawy
  • 508
  • 5
  • 14
-1

you can use momentjs like this:

 let YourDate = '1970-01-01T09:30:00.000Z'
 let time= moment(YourDate).format("hh:mm a")

Following is a stackbliz url that will help:

https://stackblitz.com/edit/angular4-momentjs-format-datetime-5etqib?file=app/app.component.ts

Amrit
  • 2,047
  • 17
  • 40
-2

You can use:

date = new Date('1970-01-01T09:30:00.000Z');

// and after this target by:
date.getFullYear()
date.getMonth()
date.getDate();

and other needed params.

Eugene
  • 171
  • 1
  • 10