當前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
JS 中关于日期
Fri Oct 31 18:00:00 UTC+0800 2008 轉換 ?2008-10-31
?
function Todate(num) { //Fri Oct 31 18:00:00 UTC+0800 2008 num = num + "";var date = "";var month = new Array();month["Jan"] = 1; month["Feb"] = 2; month["Mar"] = 3; month["Apr"] = 4; month["May"] = 5; month["Jan"] = 6;month["Jul"] = 7; month["Aug"] = 8; month["Sep"] = 9; month["Oct"] = 10; month["Nov"] = 11; month["Dec"] = 12;var week = new Array();week["Mon"] = "一"; week["Tue"] = "二"; week["Wed"] = "三"; week["Thu"] = "四"; week["Fri"] = "五"; week["Sat"] = "六"; week["Sun"] = "日";str = num.split(" ");date = str[5] + "-";date = date + month[str[1]] + "-" + str[2];return date; }?
將時間戳處理成標準格式
?
function time_deal(time_stamp){var year = time_stamp.substring(0,4);var month = time_stamp.substring(4,6);var day = time_stamp.substring(6,8);var new_time = year+"-"+month+"-"+day;return new_time; }?
計算兩個日期相差多少天
/*** 計算兩個日期相差多少天* @param strDateStart* @param strDateEnd* @returns*/ function getDays(strDateStart,strDateEnd){var strSeparator = "-"; //日期分隔符 var oDate1;var oDate2;var iDays;oDate1= strDateStart.split(strSeparator);oDate2= strDateEnd.split(strSeparator);var strDateS = new Date(oDate1[0], oDate1[1]-1, oDate1[2]);var strDateE = new Date(oDate2[0], oDate2[1]-1, oDate2[2]);iDays = parseInt(Math.abs(strDateS - strDateE ) / 1000 / 60 / 60 /24)//把相差的毫秒數轉換為天數 return iDays ; }獲取當前時間
?
/*** 獲取當前時間*/ function getNowFormatDate() {var date = new Date();var seperator1 = "-";var seperator2 = ":";var month = date.getMonth() + 1;var strDate = date.getDate();if (month >= 1 && month <= 9) {month = "0" + month;}if (strDate >= 0 && strDate <= 9) {strDate = "0" + strDate;}var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate; // + " " + date.getHours() + seperator2 + date.getMinutes() // + seperator2 + date.getSeconds();return currentdate; }?
轉載于:https://www.cnblogs.com/kuma-naya/p/6639348.html
總結
- 上一篇: Spring 依赖注入(二、注入参数)
- 下一篇: MFC接收命令行参数的三种方法