-1

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

phuzi
  • 12,078
  • 3
  • 26
  • 50
ananya
  • 1,001
  • 6
  • 33
  • 50
  • `'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

2

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,450
  • 14
  • 21
0

I think you 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 output:

27/06/2019 01:01:00

For only time use the following:

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

It will give following output:

01:01

halfer
  • 19,824
  • 17
  • 99
  • 186
sangRam
  • 315
  • 4
  • 17
-1

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
  • 301
  • 2
  • 12
-1

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

aelagawy
  • 557
  • 5
  • 16
-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,115
  • 1
  • 21
  • 41