Ⅰ js 日期格式的修改
阿速度發速度
Ⅱ js中要怎麼格式化一個時間
剛項目中需要使用js格式化輸出時間,發現js中並沒有現成的類似PHP中date()的函數。於是用模擬一個方便以後使用,代碼如下:
格式化時間
參數: formatStr 格式化串 y年,m月,d日,h小時,i分鍾,s秒鍾  預設值 "y-m-d h:i:s"
      fdate 要格式化的時間(時間戳)UTC秒數 預設值 當前時間
實例: formatDate()  當前時間默認格式 如 2011-4-12 12:51:12
      formatDate('y/m/d', 2132132131) 某時間格式為 年月日 如 2010/12/5  
function formatDate(formatStr, fdate)
{
 var fTime, fStr = 'ymdhis';
 if (!formatStr)
  formatStr= "y-m-d h:i:s";
 if (fdate)
  fTime = new Date(fdate);
 else
  fTime = new Date();
 var formatArr = [
 fTime.getFullYear().toString(),
 (fTime.getMonth()+1).toString(),
 fTime.getDate().toString(),
 fTime.getHours().toString(),
 fTime.getMinutes().toString(),
 fTime.getSeconds().toString() 
 ]
 for (var i=0; i<formatArr.length; i++)
 {
  formatStr = formatStr.replace(fStr.charAt(i), formatArr[i]);
 }
 return formatStr;
}
Ⅲ javascript中日期的格式怎麼規定的
<script language="javascript"> 
function checkform() 
{ 
s_date=document.editform.finishtime.value; //獲取值 docunment.表單名.input的名
if (s_date=="")  //判斷是否為空
{ 
alert("日期不能為空,請重新輸入!"); 
editform.action="" 
return(false); 
} 
else 
{            
re=/^20\d{2}-((0[1-9]{1})|(1[0-2]{1}))-((0[1-9]{1})|([1-2]{1}[0-9]{1})|(3[0-1]{1}))$/; //定義格式 格式 正則表達式 這里定義時間的格式20XX 0-9|0-2  01-31
if (s_date.match(re)==null) 
{ 
alert("日期輸入格式不對,正確格式為:2007-01-01"); 
document.editform.finishtime.focus(); 
return false; 
} 
</script>
Ⅳ 在JS中怎麼格式化日期
看看了你的代碼,沒毛病啊,就是輸出的是1:10, 可以加個判斷就能輸出01:10了。
if(th<10){
	th="0"+th;
}
Ⅳ 怎樣在js裡面格式化日期
格式化時間
參數: formatStr 格式化串 y年,m月,d日,h小時,i分鍾,s秒鍾 預設值 "y-m-d h:i:s"
fdate 要格式化的時間(時間戳)UTC秒數 預設值 當前時間
實例: formatDate() 當前時間默認格式 如 2011-4-12 12:51:12
formatDate('y/m/d', 2132132131) 某時間格式為 年月日 如 2010/12/5 
function formatDate(formatStr, fdate)
{
var fTime, fStr = 'ymdhis';
if (!formatStr)
formatStr= "y-m-d h:i:s";
if (fdate)
fTime = new Date(fdate);
else
fTime = new Date();
var formatArr = [
fTime.getFullYear().toString(),
(fTime.getMonth()+1).toString(),
fTime.getDate().toString(),
fTime.getHours().toString(),
fTime.getMinutes().toString(),
fTime.getSeconds().toString()
]
for (var i=0; i<formatArr.length; i++)
{
formatStr = formatStr.replace(fStr.charAt(i), formatArr[i]);
}
return formatStr;
}
Ⅵ js中日期格式控制,請教大家
直接的話是不行的,需要進行計算。
下面有個參考的示例
 
<html>
 <head>
  <title>日期判斷 周 月 季 年</title>
  <script type="text/javascript">
   var getMonthWeek = function (a, b, c) { 
    var date = new Date(a, parseInt(b) - 1, c), w = date.getDay(), d = date.getDate(); 
    return Math.ceil( (d + 6 - w) / 7 ); 
   };
   
   var getYearWeek = function (a, b, c) { 
    var date1 = new Date(a, parseInt(b) - 1, c), date2 = new Date(a, 0, 1), 
    d = Math.round((date1.valueOf() - date2.valueOf()) / 86400000); 
    return Math.ceil( (d + ((date2.getDay() + 1) - 1)) / 7 ); 
   };
   var today = new Date();//獲取當前時間
   var y = today.getFullYear();
   var m = today.getMonth()+1;
   var d = today.getDate();
   document.write("今天是:",y,"-", m, "-", d, "<br/>");
   document.write( "今天是",y,"年的第 ", getYearWeek(y, m, d), " 周<br/>" ); 
   document.write( "今天是",m,"月的第 ", getMonthWeek(y, m, d), " 周<br/>" ); 
   var quarter = "";
   var result = getYearWeek(y, m, d);
   if (m <4) {
    quarter = 1;
    week = result;
   } else if (m < 7) {
    quarter = 2;
    week = result - getYearWeek(y, 4, 1);
    var day = new Date(y, 4, 1);
    if (day.getDay() > 1) {
     week += 1;
    }
   } else if (m < 10) {
    quarter = 3;
    week = result - getYearWeek(y, 7, 1);
    var day = new Date(y, 7, 1);
    if (day.getDay() > 1) {
     week += 1;
    }
   } else {
    quarter = 4;
    week = result - getYearWeek(y, 10, 1);
    var day = new Date(y, 10, 1);
    if (day.getDay() > 1) {
     week += 1;
    }
   }
   document.write( "今天是第",quarter,"季度的第 ", week, " 周" ); 
  </script>
 </head>
 <body>
 </body>
</html>
Ⅶ JS怎麼修改時間顯示的格式。感謝
樣例代碼:
<html>
<head>
<title>知道</title>
<metahttp-equiv="Content-Type"content="text/html;charset=utf-8"/>
<styletype="text/css">
#time{font-size:24px;}
</style>
</head>
<body>
<scriptlanguage=JavaScript>
varformatZero=function(n){
return(n-9>0)?n:'0'+n;
}
varnow=newDate();//當前時間
varisjx=0;
functionGetServerTime(){
vard=now.getYear()+"/"+now.getMonth()+"/"+now.getDate()+"00:00:00";//設置每天的16:30為節點
varurodz=newDate(d);
now.setTime(now.getTime()+250);
days=(urodz-now)/1000/60/60/24;
daysRound=Math.floor(days);
hours=(urodz-now)/1000/60/60-(24*daysRound);
hoursRound=Math.floor(hours);
minutes=(urodz-now)/1000/60-(24*60*daysRound)-(60*hoursRound);
minutesRound=Math.floor(minutes);
seconds=(urodz-now)/1000-(24*60*60*daysRound)-(60*60*hoursRound)-(60*minutesRound);
secondsRound=Math.round(seconds);
if((hoursRound==0&&minutesRound==0&&secondsRound==0)){//都等於0說明過了16:30
isjx=1;
}
hoursRound=formatZero(hoursRound);
minutesRound=formatZero(minutesRound);
secondsRound=formatZero(secondsRound);
//判斷
if(isjx==0&&(parseFloat(now.toTimeString().substr(0,2)+now.toTimeString().substr(3,3).substr(0,2)+now.toTimeString().substr(6,7))<=162959)){
document.getElementById("time").innerHTML="距離開始還有"+hoursRound+"小時"+minutesRound+"分鍾"+secondsRound+"秒";
}else{
document.getElementById("time").innerHTML="距離結束還有"+hoursRound+"小時"+minutesRound+"分鍾"+secondsRound+"秒";
}
}
setInterval("GetServerTime()",250);
</script>
<spanid="time"></span>
</body>
</html>
希望對你有幫助。
Ⅷ js時間格式化
對Date的擴展,將 Date 轉化為指定格式的String   
 月(M)、日(d)、小時(h)、分(m)、秒(s)、季度(q) 可以用 1-2 個佔位符,   
年(y)可以用 1-4 個佔位符,毫秒(S)只能用 1 個佔位符(是 1-3 位的數字)   
// 例子:   
// (new Date()).Format("yyyy-MM-dd hh:mm:ss.S") ==> 2006-07-02 08:09:04.423   
// (new Date()).Format("yyyy-M-d h:m:s.S")      ==> 2006-7-2 8:9:4.18   
Date.prototype.Format = function(fmt)   
{ //author: meizz   
  var o = {   
    "M+" : this.getMonth()+1,                 //月份   
    "d+" : this.getDate(),                    //日   
    "h+" : this.getHours(),                   //小時   
    "m+" : this.getMinutes(),                 //分   
    "s+" : this.getSeconds(),                 //秒   
    "q+" : Math.floor((this.getMonth()+3)/3), //季度   
    "S"  : this.getMilliseconds()             //毫秒   
  };   
  if(/(y+)/.test(fmt))   
    fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));   
  for(var k in o)   
    if(new RegExp("("+ k +")").test(fmt))   
  fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));   
  return fmt;   
}
Ⅸ js時間格式問題
var time = '2015-07-28 11:00:00';
	time = time.replace('-','/');
	var date = new Date(Date.parse(time));
	var hour = date.getHours();
Ⅹ 如何通過JS設置日期控制的格式
直接的話是不行的,需要進行計算。 下面有個參考的示例 日期版判斷 周 月權 季 年 var getMonthWeek = function (a, b, c) { var date = new Date(a, parseInt(b) - 1, c), w = date.getDay(), d = date.getDate(); return Math.ceil( (d + 6 - w)