js日期时间格式化

const formatTimes = date => {
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()
  const hour = date.getHours()
  const minute = date.getMinutes()
  const second = date.getSeconds()

  return [year, month, day].map(doubleNumber).join(‘/‘) + ‘ ‘ + [hour, minute, second].map(doubleNumber).join(‘:‘)
}

const doubleNumber = num => {
  num = num.toString()
  return num[1] ? num : ‘0‘ + num
}

module.exports = {
  formatTime: formatTimes
}

原文地址:https://www.cnblogs.com/aloehui/p/9076256.html

时间: 2024-07-31 16:43:52

js日期时间格式化的相关文章

js -- 日期时间格式化

/** * js日期时间格式化 * @param date 时间读对象 * @param format 格式化字符串 例如:yyyy年MM月dd日 hh时mm分ss秒 * @returns {string} 返回格式化后的字符串 */function dateFormat (date, format) { var o = { "M+": date.getMonth() + 1, //month "d+": date.getDate(), //day "h+

js日期/时间格式化方法

一.javascript Date format(日期格式化) 方法一: // 对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:0

String.Format,DateTime日期时间格式化集锦

DateTime dt = DateTime.Now;//2010年10月4日 17点05分 string str = ""; //str = string.Format("{0:y yy yyy yyyy}", dt); //10 10 2010 2010 //str = String.Format("{0:M MM MMM MMMM}", dt); //10 10 十月 十月 //str = String.Format("{0:d

String.Format,DateTime日期时间格式化

DateTime dt = DateTime.Now;//2010年10月4日 17点05分            string str = "";            //str = string.Format("{0:y yy yyy yyyy}", dt); //10 10 2010 2010            //str = String.Format("{0:M MM MMM MMMM}", dt); //10 10 十月 十月 

Swift教程_基础技术_获取当前日期时间、日期时间格式化及转换

Swift教程_基础技术_类型转换(父子类转换:Int.Double.String转换) Swift教程_基础技术_获取当前日期时间.日期时间格式化及转换 1.获取当前日期时间 var nowDate = NSDate() var formatter = NSDateFormatter() formatter.dateFormat = "yyyy-MM-dd HH:mm:ss" var dateString = formatter.stringFromDate(nowDate) pri

原生js日期时间插件鼠标点击文本框弹出日期时间表格选择日期时间

原文出处 (这是我从互联网上搜来的,感觉能满足各方面的需求.个人感觉挺不错的,所以后期修改了一下向大家推荐!) 效果图: html代码: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org

JS日期时间选择器

本文介绍一种日期和时间选择器的用法.此选择器由jqueryUI实现,支持精确到毫秒的时间选择. 此选择器项目地址为http://trentrichardson.com/examples/timepicker/ Demo地址为:http://www.helloweba.com/demo/timepicker/ 下载地址:http://download.csdn.net/detail/yanwushu/7721933 效果图 另外关于js时间选择器还可以参考其他项目 http://www.bootc

PHPCMS V9调用时间标签 |日期时间格式化

PHPCMS V9 如何调用时间标签,下面分享常见的调用时间标签 |日期时间格式化 1.日期时间格式化显示: a标准型:{date('Y-m-d H:i:s', $rs['inputtime'])} 输出为:2013-01-31 13:15:10 b拆分型:{date('Y',$rs[inputtime])}年{date('m',$rs[inputtime])}月{date('d',$rs[inputtime])}日 输出为:2013年01月31日 c扩展型: {date('Y',$inputt

js Date 时间格式化的扩展

js Date 时间格式化的扩展: 1 Date.prototype.format = function (fmt) { 2 var o = { 3 "M+": this.getMonth() + 1, //月 4 "d+": this.getDate(), //日 5 "h+": this.getHours() % 12 == 0 ? 12 : this.getHours() % 12, //时 6 "H+": this.g