Format date in jquery- from Sat Mar 03 2012 14:16:05 GMT+0530 to 03/03/2012

怎甘沉沦 提交于 2019-12-11 05:07:00

问题


How can I format this date?

 <li>Sat Mar 03 2012 14:16:05 GMT+0530 (India Standard Time)</li>

I used new date() function to get date in this li. I want date like this 03/03/2012


回答1:


function dateFormat(){
    var d = new Date();

    date = d.getDate();
    date = date < 10 ? "0"+date : date;

    mon = d.getMonth()+1;
    mon = mon < 10 ? "0"+mon : mon;

    year = d.getFullYear()

    return (date+"/"+mon+"/"+year);
}

dateFormat();



回答2:


All you need to do is tell the date function to format the date to the kind of output you want.

(Assuming you are using date function of JavaScript, which you did mention above.)

http://www.webdevelopersnotes.com/tips/html/10_ways_to_format_time_and_date_using_javascript.php3

<script type="text/javascript">
    <!--

    var d = new Date();  
    var curr_date = d.getDate();  
    var curr_month = d.getMonth(); 
    var curr_year = d.getFullYear();

    document.write(curr_date + "-" + curr_month + "-" + curr_year);

    //-->
</script>

OR

http://blog.stevenlevithan.com/archives/date-time-format

OR

http://archive.plugins.jquery.com/project/jquery-dateFormat

<script>
    $.format.date("2009-12-18 10:54:50.546", "dd/MM/yyyy");
</script>


来源:https://stackoverflow.com/questions/9544949/format-date-in-jquery-from-sat-mar-03-2012-141605-gmt0530-to-03-03-2012

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!