Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Format Date time in AngularJS

How do I properly display the date and time in AngularJS?

The output below shows both the input and the output, with and without the AngularJS date filter:

In: {{v.Dt}}   AngularJS: {{v.Dt | date:'yyyy-MM-dd HH:mm:ss Z'}} 

This prints:

In: 2012-10-16T17:57:28.556094Z  AngularJS: 2012-10-16T17:57:28.556094Z 

The desired display format is 2010-10-28 23:40:23 0400 or 2010-10-28 23:40:23 EST

like image 472
bsr Avatar asked Oct 16 '12 18:10

bsr


People also ask

How to add date format in angular?

You can create class for property like wise I have use environment class for date format DATE_FORMAT and assign by default dd-MM-yyyy format and use in date pipe. By this approach only change the value of DATE_FORMAT and we can easily change the format of date else where. Save this answer. Show activity on this post.

How do you convert date to yyyy mm dd format in TypeScript?

The simplest way to convert your date to the yyyy-mm-dd format, is to do this: var date = new Date(“Sun May 11,2014”); var dateString = new Date(date. getTime() – (date. getTimezoneOffset() * 60000 )) .

How do you format a date?

Press CTRL+1. In the Format Cells box, click the Number tab. In the Category list, click Date, and then choose a date format you want in Type.


1 Answers

Your code should work as you have it see this fiddle.

You'll have to make sure your v.Dt is a proper Date object for it to work though.

{{dt | date:'yyyy-MM-dd HH:mm:ss Z'}} 

or if dateFormat is defined in scope as dateFormat = 'yyyy-MM-dd HH:mm:ss Z':

{{dt | date:dateFormat }} 
like image 52
Gloopy Avatar answered Oct 11 '22 09:10

Gloopy