关于浏览器文化如何格式化JavaScript日期? [英] How format JavaScript Date with regard to the browser culture?

查看:136
本文介绍了关于浏览器文化如何格式化JavaScript日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要格式化JavaScript Date对象。对于浏览器使用的文化,应该显示短格式的日期和时间,例如:

I need to format the JavaScript Date object. It should display date and time in short format with regard to the culture that browser is using, for example:

20/10/2011 10:20 PM
10.20.2011 22:20

我该怎么做最好用jQuery)?

How do I do this (preferably with jQuery)?

推荐答案

Date()对象会让您得到客户端时间(现场演示这里):

The Date() object will get you the client time (live demo here):

var now=new Date();
alert(now.toLocaleString());

JS和jQuery没有内置格式函数。要格式化,请使用 format()(1.2kb)这里,然后以下代码将产生一种格式,如10/10/2012 8:50 pm:

JS and jQuery don't have a built in format function. To format it differently use a function like format() (1.2kb) here and then the following code will produce a format like "10/10/2012 8:50pm" :

var now=new Date();    
alert( now.format("mm/dd/yy h:MM:ss TT") );

这篇关于关于浏览器文化如何格式化JavaScript日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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