Flask-Moment ---- exploration,

Source: Internet
Author: User

Flask-Moment ---- exploration,

 Preface:Flask-Moment is relatively simple in all flask extensions, but there are still many things to understand. let's take a look at the application of flask-moment in the flask project.

  

First of all, we need to understand what flask-moment is for, and extract a paragraph from the dog book:

       There is an excellent open-source client code library developed using JavaScript, named moment. js (http: // momentjs.

Com/), which can render the date and time in the browser. Flask-Moment is a Flask program extension that can
Moment. js is integrated into the Jinja2 template.

This section is easy to understand. Simply put, the time is displayed on the webpage. The specific operations are as follows:

 

   1. initialize flask-moment     

   from flask_sqlalchemy import SQLAlchemy   moment=Moment()

 

2. conditions required for applying flask-moment   

    {{ moment.include_moment() }}    {{ moment.include_jquery() }}

Import moment and jquery. If bootstrap is applied to your project, you do not need to import jquery.

The two-line code can be stored in the base.html style to facilitate inheritance of Other templates.

 

Iii. Actual Practice

# Import from datetime import datetime time = datetime. utcnow () # pass as a parameter of the view Function

    

  
<P> the page is opened at {moment (time ). format ('yyyy-M-D, H: mm: ss A, week w ')}}. </p> <p> past: {moment (time ). fromNow (refresh = True) }}</p>

How can this problem be understood?

   Moment (time). format ('yyyy-mm-dd, H: mm: ss A, week w ')

# Obtain the current time and display it at a certain time

 Moment (time). fromNow (refresh = True)

# FromNow indicates the relative time, which indicates how long the last time has elapsed. When refresh = True is passed, the time will be displayed on the page, for example, several seconds or minutes.

   

I have questions at the beginning, huh? YYYY-mmonth... what are these things? I didn't explain it clearly. In fact, if you have good English, you can understand year very well!

The details are as follows:

YYYY 2014 Year
YY 14 The year in two characters.
Q 1..4 Quarter
M MM 4..04 Month
MMM MMMM April. April Displays the month according to the settings in moment. locale ().
D DD 1..31 The day of January 1, January
Do 1 .. 31 The day of January 1, January
DDD DDDD 1..365 Day of the year
X 1410715640.579 Timestamp
x 1410715640579 Timestamp

 

Of course there are many moment. js methods, specific visit moment. js Chinese official website: http://momentjs.cn/

      

 

  

  

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.