极乐门资源网 Design By www.ioogu.com
示例一:
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>TT</title> <script src="/UploadFiles/2021-04-02/jquery.js">示例二:
<script type="text/javascript"> var date = new Date(); document.writeln(date); //Thu Jan 08 2015 01:25:53 GMT+0800 (中国标准时间) document.writeln(Date.parse()); //NaN document.writeln(Date.parse('6/10/2014')); //1402329600000 毫秒数 document.writeln(Date.parse('Thu Jan 08 2015 01:25:53')); //1420651553000 毫秒数 document.writeln(Date.UTC()); //NaN //日期格式化方法 document.writeln('<br/>'); document.writeln(date.toDateString()); //Thu Jan 08 2015 document.writeln('<br/>') document.writeln(date.toTimeString()); //01:39:08 GMT+0800 (中国标准时间) document.writeln('<br/>') document.writeln(date.toLocaleDateString()); //2015年1月8日 document.writeln('<br/>') document.writeln(date.toLocaleTimeString()); //上午1:39:08 document.writeln('<br/>') document.writeln(date.toUTCString()); //Wed, 07 Jan 2015 17:39:08 GMT //一些set,get方法 </script>示例三:
Date.prototype.Format = function(formatStr) { var str = formatStr; var Week = ['日', '一', '二', '三', '四', '五', '六']; str = str.replace(/yyyy|YYYY/, this.getFullYear()); str = str.replace(/yy|YY/, (this.getYear() % 100) > 9 "htmlcode">Date.prototype.toString=function(format,loc){ var time={}; time.Year=this.getFullYear(); time.TYear=(""+time.Year).substr(2); time.Month=this.getMonth()+1; time.TMonth=time.Month<10"0"+time.Month:time.Month; time.Day=this.getDate(); time.TDay=time.Day<10"0"+time.Day:time.Day; time.Hour=this.getHours(); time.THour=time.Hour<10"0"+time.Hour:time.Hour; time.hour=time.Hour<13"0"+time.hour:time.hour; time.Minute=this.getMinutes(); time.TMinute=time.Minute<10"0"+time.Minute:time.Minute; time.Second=this.getSeconds(); time.TSecond=time.Second<10"0"+time.Second:time.Second; time.Millisecond=this.getMilliseconds(); time.Week=this.getDay(); var MMMArrEn=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]; var MMMArr=["一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"]; var WeekArrEn=["Sun","Mon","Tue","Web","Thu","Fri","Sat"]; var WeekArr=["星期日","星期一","星期二","星期三","星期四","星期五","星期六"]; var oNumber=time.Millisecond/1000; if(format!=undefined && format.replace(/\s/g,"").length>0){ if(loc!=undefined && loc =="en"){ MMMArr=MMMArrEn.slice(0); WeekArr=WeekArrEn.slice(0); } format=format .replace(/yyyy/ig,time.Year) .replace(/yyy/ig,time.Year) .replace(/yy/ig,time.TYear) .replace(/y/ig,time.TYear) .replace(/MMM/g,MMMArr[time.Month-1]) .replace(/MM/g,time.TMonth) .replace(/M/g,time.Month) .replace(/dd/ig,time.TDay) .replace(/d/ig,time.Day) .replace(/HH/g,time.THour) .replace(/H/g,time.Hour) .replace(/hh/g,time.Thour) .replace(/h/g,time.hour) .replace(/mm/g,time.TMinute) .replace(/m/g,time.Minute) .replace(/ss/ig,time.TSecond) .replace(/s/ig,time.Second) .replace(/fff/ig,time.Millisecond) .replace(/ff/ig,oNumber.toFixed(2)*100) .replace(/f/ig,oNumber.toFixed(1)*10) .replace(/EEE/g,WeekArr[time.Week]); } else{ format=time.Year+"-"+time.Month+"-"+time.Day+" "+time.Hour+":"+time.Minute+":"+time.Second; } return format; } var d=new Date(); console.log(d.toString()); //2014-7-27 9:26:52 console.log(d.toString("")); //2014-7-27 9:26:52 console.log(d.toString("yyyy-MM-dd HH:mm:ss")); //2014-07-27 09:26:52 console.log(d.toString("yyyy年MM月dd日 HH:mm:ss")); //2014年07月27日 09:26:52 console.log(d.toString("yyyy-MM-dd HH:mm:ss fff")); //2014-07-27 09:26:52 237 console.log(d.toString("yyyy年 MMM dd EEE")); //2014年 七月 27 星期五 console.log(d.toString("yyyy MMM dd EEE","en")); //2014 Jul 27 Fri示例五:时间个性化输出功能
/* 1、< 60s, 显示为“刚刚” 2、>= 1min && < 60 min, 显示与当前时间差“XX分钟前” 3、>= 60min && < 1day, 显示与当前时间差“今天 XX:XX” 4、>= 1day && < 1year, 显示日期“XX月XX日 XX:XX” 5、>= 1year, 显示具体日期“XXXX年XX月XX日 XX:XX” */ function timeFormat(time){ var date = new Date(time), curDate = new Date(), year = date.getFullYear(), month = date.getMonth() + 10, day = date.getDate(), hour = date.getHours(), minute = date.getMinutes(), curYear = curDate.getFullYear(), curHour = curDate.getHours(), timeStr; if(year < curYear){ timeStr = year +'年'+ month +'月'+ day +'日 '+ hour +':'+ minute; }else{ var pastTime = curDate - date, pastH = pastTime/3600000; if(pastH > curHour){ timeStr = month +'月'+ day +'日 '+ hour +':'+ minute; }else if(pastH >= 1){ timeStr = '今天 ' + hour +':'+ minute +'分'; }else{ var pastM = curDate.getMinutes() - minute; if(pastM > 1){ timeStr = pastM +'分钟前'; }else{ timeStr = '刚刚'; } } } return timeStr; }以上所述就是本文的全部内容了,希望大家能够喜欢。
极乐门资源网 Design By www.ioogu.com
极乐门资源网
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
极乐门资源网 Design By www.ioogu.com
暂无javascript格式化日期时间方法汇总的评论...
RTX 5090要首发 性能要翻倍!三星展示GDDR7显存
三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。
首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。
据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。
更新日志
2025年01月18日
2025年01月18日
- 小骆驼-《草原狼2(蓝光CD)》[原抓WAV+CUE]
- 群星《欢迎来到我身边 电影原声专辑》[320K/MP3][105.02MB]
- 群星《欢迎来到我身边 电影原声专辑》[FLAC/分轨][480.9MB]
- 雷婷《梦里蓝天HQⅡ》 2023头版限量编号低速原抓[WAV+CUE][463M]
- 群星《2024好听新歌42》AI调整音效【WAV分轨】
- 王思雨-《思念陪着鸿雁飞》WAV
- 王思雨《喜马拉雅HQ》头版限量编号[WAV+CUE]
- 李健《无时无刻》[WAV+CUE][590M]
- 陈奕迅《酝酿》[WAV分轨][502M]
- 卓依婷《化蝶》2CD[WAV+CUE][1.1G]
- 群星《吉他王(黑胶CD)》[WAV+CUE]
- 齐秦《穿乐(穿越)》[WAV+CUE]
- 发烧珍品《数位CD音响测试-动向效果(九)》【WAV+CUE】
- 邝美云《邝美云精装歌集》[DSF][1.6G]
- 吕方《爱一回伤一回》[WAV+CUE][454M]