jQuery 从数据库转换日期格式
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19535240/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Converting date format from database
提问by Jainul Khan
I have a date coming from database as Oct 10 2013 12:00AM
我有一个来自数据库的日期为2013 年 10 月 10 日 12:00AM
I want to convert it as 10/10/2013 like mm/dd/yy.
我想将其转换为 10/10/2013,如 mm/dd/yy。
回答by atom217
Use the javascript date object.
<script>
var date = new date('2013-04-01T19:45:11.000Z');
var day = date.getDate();
var month = date.getMonth();
var year = date.getFullYear();
document.write(year + '-' + month + '-' + day);
</script>
回答by Milson
Do use Server side code behind as follows:
请按如下方式使用服务器端代码:
DateTime matchDay = DateTime.Parse("10/10/2013 12:15:15 AM");
String.Format("{0:MM/dd/yyyy}", matchDay); ; //10/10/2013
For Client side use :
对于客户端使用:
If you are already using jQuery UIin your project, then you can use the built-in datepicker method for formatting your date object:
如果你已经在你的项目中使用了jQuery UI,那么你可以使用内置的 datepicker 方法来格式化你的日期对象:
$.datepicker.formatDate('mm/dd/yy', new Date(2013, 10 - 1, 10));