Date to String对象转换 [英] Date to String object conversion

查看:85
本文介绍了Date to String对象转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下代码片段将Date对象转换为字符串。

I have use the following code snippet to convert the Date object to string .

 var startDate = new Date();
 var result = Globalize.parseDate(startDate, "MM/DD/YYYY");

但它将返回空值。如何将Date对象转换为字符串特定格式?

but it will return the null value. How to convert the Date object to string specific format ?

推荐答案

要了解所有可能的方法,请检查 此链接 out。

To know all possible ways, check this link out.

我把所有 DEMOS放在这里......

I've put all the DEMOS here...

<script type="text/javascript">
    var d = new Date();
    var curr_date = d.getDate();
    var curr_month = d.getMonth() + 1; //Months start with zero
    var curr_year = d.getFullYear();
    document.write(curr_month + "/" + curr_date + "/" + curr_year);
</script>



MOMENT.JS:



在此下载...

MOMENT.JS:

Download here...

<script>    
    var a = moment([2010, 1, 14, 15, 25, 50, 125]);
    a.format("MM/DD/YYYY,");    
</script>

不想下载,只需添加以下行:

Don't want to download, simply add this line:

<script src="http://momentjs.com/downloads/moment.min.js"></script>



jQuery UI:



jQuery UI:

$.datepicker.formatDate('yy-mm-dd', new Date(2007, 1 - 1, 26));



IE:



IE:

var d1=new Date();
d1.toString('MM-dd-yyyy');



全球化:



Globalize:

var startDate = new Date();
var result = Globalize.format(startDate, "MM/DD/YYYY");

这篇关于Date to String对象转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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