DD/MM/YYYY Moment.js 中的日期格式
DD/MM/YYYY Date format in Moment.js
如何使用 moment.js 将当前日期更改为这种格式 (DD/MM/YYYY)?
我试过下面的代码。
$scope.SearchDate = moment(new Date(), "DD/MM/YYYY");
但它是 return 0037-11-24T18:30:00.000Z
。没有帮助格式化当前日期。
需要调用format()函数获取格式化后的值
$scope.SearchDate = moment(new Date()).format("DD/MM/YYYY")
//or $scope.SearchDate = moment().format("DD/MM/YYYY")
您使用的语法用于parse 通过使用指定格式
给定字符串到日期对象
这实际上对我有用:
moment(mydate).format('L');
你可以用这个
moment().format("DD/MM/YYYY");
但是,这个 returns 是今天指定格式的日期字符串,而不是时刻日期对象。执行以下操作将使它成为您想要的格式的时刻日期对象。
var someDateString = moment().format("DD/MM/YYYY");
var someDate = moment(someDateString, "DD/MM/YYYY");
这对我有用
var dateToFormat = "2018-05-16 12:57:13"; //TIMESTAMP
moment(dateToFormat).format("DD/MM/YYYY"); // you get "16/05/2018"
对于所有使用 react-moment
的人:
简单地使用 format
道具到你需要的格式:
const now = new Date()
<Moment format="DD/MM/YYYY">{now}</Moment>
如何使用 moment.js 将当前日期更改为这种格式 (DD/MM/YYYY)?
我试过下面的代码。
$scope.SearchDate = moment(new Date(), "DD/MM/YYYY");
但它是 return 0037-11-24T18:30:00.000Z
。没有帮助格式化当前日期。
需要调用format()函数获取格式化后的值
$scope.SearchDate = moment(new Date()).format("DD/MM/YYYY")
//or $scope.SearchDate = moment().format("DD/MM/YYYY")
您使用的语法用于parse 通过使用指定格式
给定字符串到日期对象这实际上对我有用:
moment(mydate).format('L');
你可以用这个
moment().format("DD/MM/YYYY");
但是,这个 returns 是今天指定格式的日期字符串,而不是时刻日期对象。执行以下操作将使它成为您想要的格式的时刻日期对象。
var someDateString = moment().format("DD/MM/YYYY");
var someDate = moment(someDateString, "DD/MM/YYYY");
这对我有用
var dateToFormat = "2018-05-16 12:57:13"; //TIMESTAMP
moment(dateToFormat).format("DD/MM/YYYY"); // you get "16/05/2018"
对于所有使用 react-moment
的人:
简单地使用 format
道具到你需要的格式:
const now = new Date()
<Moment format="DD/MM/YYYY">{now}</Moment>