以dd / mm / yyyy hh:mm:ss格式转换日期对象 [英] Convert date object in dd/mm/yyyy hh:mm:ss format

查看:330
本文介绍了以dd / mm / yyyy hh:mm:ss格式转换日期对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个datetime对象,其值如下

I have a datetime object and its value is as follows

2017-03-16T17:46:53.677

有人可以让我知道如何将其转换为dd / mm / yyyy hh:mm:ss格式
我在Lott上进行了搜索,但找不到此特定输入的格式转换。

Can someone please let me know how to convert this to dd/mm/yyyy hh:mm:ss format I googled a lott and could not find format conversion for this particular input.

推荐答案

您可以按照其他文章中所述完全格式化字符串。但是我认为您最好在date对象中使用语言环境功能?

You can fully format the string as mentioned in other posts. But I think your better off using the locale functions in the date object?

var d = new Date("2017-03-16T17:46:53.677"); 
console.log( d.toLocaleString() ); 

编辑:

ISO 8601 (您正在构建的格式用)表示时区在字符串的末尾附加 [{+ |-} hh] [:mm]

ISO 8601 ( the format you are constructing with ) states the time zone is appended at the end with a [{+|-}hh][:mm] at the end of the string.

所以您可以这样做:

var tzOffset = "+07:00" 
var d = new Date("2017-03-16T17:46:53.677"+ tzOffset);
console.log(d.toLocaleString());
var d = new Date("2017-03-16T17:46:53.677"); //  assumes local time. 
console.log(d.toLocaleString());
var d = new Date("2017-03-16T17:46:53.677Z"); // UTC time
console.log(d.toLocaleString());

编辑:

只需知道语言环境函数会显示日期和时间以用户语言和位置的方式。欧洲日期为 dd / mm / yyyy ,美国日期为 mm / dd / yyyy

Just so you know the locale function displays the date and time in the manner of the users language and location. European date is dd/mm/yyyy and US is mm/dd/yyyy.

var d = new Date("2017-03-16T17:46:53.677");
console.log(d.toLocaleString("en-US"));
console.log(d.toLocaleString("en-GB"));

这篇关于以dd / mm / yyyy hh:mm:ss格式转换日期对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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