美文网首页
js格式化日期

js格式化日期

作者: 佛系码农 | 来源:发表于2018-07-13 10:34 被阅读0次

//js获取定制格式日期
function getFormatDate() {
var nowDate = new Date();
var year = nowDate.getFullYear();
var month = nowDate.getMonth() + 1 < 10 ? "0" + (nowDate.getMonth() + 1) : nowDate.getMonth() + 1;
var date = nowDate.getDate() < 10 ? "0" + nowDate.getDate() : nowDate.getDate();
var hour = nowDate.getHours() < 10 ? "0" + nowDate.getHours() : nowDate.getHours();
var minute = nowDate.getMinutes() < 10 ? "0" + nowDate.getMinutes() : nowDate.getMinutes();
var second = nowDate.getSeconds() < 10 ? "0" + nowDate.getSeconds() : nowDate.getSeconds();
//return year + "/" + month + "/" + date + " " + hour + ":" + minute + ":" + second;
//return year + "/" + month + "/" + date + " " + hour + ":" + minute;
return year + "/" + month + "/" + date;// + " " + hour + ":" + minute;
}

相关文章

  • Javascript日期处理类库

    Moment.js Javascript日期处理类库 http://momentjs.cn/ CDN 日期格式化 ...

  • 日期时间格式化

    Js获取当前日期时间和格式化日期 ](javascript:void(0); "复制代码") var myDate...

  • JS好用的库

    JS 日期处理Moment.js 格式化和操作数字Numeral.js 加密库crypto-jsSparkMD5 ...

  • 日期格式化等方法

    日期格式化和其他常用方法插件 src/assets/js/dateFilter.js 使用方法 直接在js中调用方...

  • JavaScript--Date

    JS中月份从0开始 获取日期 格式化 个位数的使用padding补0 设置日期

  • js时间戳与字符串转换

    1.日期字符串转时间戳 2.时间戳转换时间 js日期时间格式化,可直接复制打包成js文件使用

  • js格式化日期

    //js获取定制格式日期function getFormatDate() {var nowDate = new D...

  • js日期格式化

    需求 需要将当前日期格式化成“2017-07-25”形式 实现 TIPS 1、由于getMonth()是从0开始,...

  • js日期格式化

    重写了一个格式化日期的方法,支持把日期格式或时间戳按指定的格式输出,应该能满足大多数时候的需求。 说明 案例 源代码如下

  • Js日期格式化

网友评论

      本文标题:js格式化日期

      本文链接:https://www.haomeiwen.com/subject/afhjpftx.html