Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to convert date by string with vuejs

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article focuses on "how to convert a string to a date by vuejs". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "how to convert a string to a date by vuejs".

Vuejs to achieve string date conversion method: 1, install moment package; 2, introduce moment;3 in the component, use "let str = moment (new Date ()) .format (" YYYY-MM-DD hh:mm:ss ")" method conversion can be.

This article operating environment: Windows7 system, Vue2.9.6 version, DELL G3 computer

How does vuejs convert date from string to date?

Date format conversion in JS and vue:

1. Get the current time:

Var now=new Date (); / / Tue Oct 17 2017 18:08:40 GMT+0800 (China Standard time)

Get the date of the current time

New Date (). GetDate () / / 17 new Date (). ToLocaleString () / 6:08:40 on 2017-10-17

two。 Quote moment.js to convert standard time into YYYY-MM-DD hh:mm:ss

Var time=moment (new Date ()) .format ("YYYY-MM-DD hh:mm:ss"); / 2017-10-17 06:08:40 var time=moment (new Date ()) .format ("DD"); / / 17

Gets the second day of the current time

Moment (new Date (). SetDate (new Date (). GetDate () + 2). Format ("YYYY-MM-DD hh:mm:ss") / / 2017-10-19 06:08:40

3. Convert standard time to timestamp

New Date () .getTime () / / 1508234920433

Convert a YYYY-MM-DD date to a timestamp

Var stringTime = "2014-07-10 10:21:12"; var timestamp2 = Date.parse (new Date (stringTime)); console.log (timestamp2); / / 1500286120000

4. Convert timestamps to standard time and YYYY-MM-DD

New Date (parseInt ('1508234920433') / / Tue Oct 17 2017 18:08:40 GMT+0800 (China Standard time) moment (new Date (parseInt ('1508234920433')) .format ("YYYY-MM-DD hh:mm:ss") / / 2017-10-19 06:08:40

How to use moment format to convert dates in 5.vue?

1) install the moment package: npm install moment first

2) introduce moment: import moment from "moment" into the component

3) use in the component: let str = moment (new Date ()) .format ("YYYY-MM-DD hh:mm:ss") / / 2018-04-24 09:55:40

At this point, I believe you have a deeper understanding of "vuejs how to convert a date into a string". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report