如何在 Vue.js 中格式化当前日期格式 [英] How to format the current date format in Vue.js

查看:200
本文介绍了如何在 Vue.js 中格式化当前日期格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在 Vue.js 中获取当前日期.

I need to get the current date in Vue.js.

为此,我使用了以下方法.

For that, I used the following method.

today_date: new Date().toJSON().slice(0,10).replace(/-/g,'.')

today_date 将以 2019.09.11 格式给出日期.

today_date will give the date as 2019.09.11 format.

有什么方法可以自定义这种格式吗?实际上我需要以 11.09.2019 格式获取日期.但是最好知道是否有解决方案可以获取多种格式的日期.

Is there any method to customize this format? Actually I need to get the date as 11.09.2019 format. But it's better to know whether there are solutions to get the date in several formats.

推荐答案

在纯 Javascript 中,您应该通过获取日、月和年来硬编码您想要的格式,并将它们连接起来以获得您想要的,但我建议使用 moment.js 库来轻松格式化日期,例如:

In pure Javascript you should hard code the format that you want by getting the day, month and year, and concatenate them to get what you want, but i recommend to use the moment.js library to format the date easily like :

moment().format('MMMM Do YYYY, h:mm:ss a'); // September 11th 2019, 10:52:10 am
moment().format('dddd');                    // Wednesday
moment().format("MMM Do YY");               // Sep 11th 19
moment().format('YYYY [escaped] YYYY');    

这篇关于如何在 Vue.js 中格式化当前日期格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆