AngularJS date formatting

Source: Internet
Author: User
AngularJS supports date formatting in two forms: HTML pages and JS Code, angularJS filters $ filter AngularJS are designed to overcome the shortcomings of HTML in application construction. HTML is a well-designed declarative language for static text display, but it seems weak to build WEB applications. So I did some work (you can also think it is a little trick) to let the browser do what I want.

AngularJS supports date formatting in two forms: HTML pages and AngularJS code filters $ filter.

HTML: date_expression is the date type variable you set in $ scope (note that the date object must be correct). It is also the date to be displayed. | it is a delimiter, the first parameter date after the separator indicates that the filter type is to filter the date, and the second parameter format indicates what your date will look like, such as yyyy-MM-dd, the last timezone is the time zone (optional parameter), which is applicable to international websites.

{Date_expression | date: format: timezone }}

You can use the {} expression or ng-bind or ng-model.

{MyDate | date: 'medium '}}

In Javascript code, it is written as follows:

Var myJsDate = $ filter ('date') ($ scope. myDate, 'yyyy-MM-dd ');

In this way, the variable myJsDate you declare will be able to get the value after myDate formatting in $ scope.

The above is a detailed explanation of AngularJS date formatting provided by the editor. I hope you will like it.

For more details about AngularJS date formatting, refer to the PHP Chinese website!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.