[英]How to convert dateTime format in javascript
我如何將datetime 5/8/2011 12:00:00 AM
(m / d / yyyy)轉換為dd-MMM-yyyy,如JavaScript中08-May-2011
年08-May-2011
。
該鏈接是您可以使用的很好的資源。
http://blog.stevenlevithan.com/archives/date-time-format
另外,您需要獲取單個部分並根據需要將它們連接起來,如下所示。
var now = new Date();
var hour = now.getHours();
var minute = now.getMinutes();
var second = now.getSeconds();
var monthnumber = now.getMonth();
var monthday = now.getDate();
var year = now.getYear();
String myOutput = monthday + "-" + monthnumer + "-" + year;
要獲取月份名稱而不是月份編號,您需要定義如下數組
var arrMonths = new Array ("Jan","Feb"....};
String myOutput = monthday + "-" + arrMonths[monthnumer-1] + "-" + year;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.