js 日期时间格式化,年月日时分秒
1. formatDate.js
export function formatDate(date, fmt) {var currentDate = new Date(date);var o = {"M+": currentDate.getMonth() + 1, //月份"d+": currentDate.getDate(), //日"h+": currentDate.getHours(), //小时"m+": currentDate.getMinutes(), //分"s+": currentDate.getSeconds(), //秒"q+": Math.floor((currentDate.getMonth() + 3) / 3), //季度"S": currentDate.getMilliseconds() //毫秒};if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (currentDate.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;
}
2. 调用
项目中:import {formatDate} from "./formatDate.js"
js中:formatDate(new Date(), 'yyyy-MM-dd hh:mm:ss'); // 格式化当前时间:2018-07-08 10:10:10var time = "2018-08-08T08:00:28";1: formatDate(time, 'yyyy/MM/dd hh:mm:ss'); // 格式化为其他格式:2018/08/08 08:00:282: time.replace("T", " "); // replace简单处理:2018-08-08 08:00:28
js 日期时间格式化,年月日时分秒相关推荐
- JS获取当前时间(年月日时分秒)
JS获取当前时间(年月日时分秒) JS获取当前时间(年月日时分秒) 代码直接撸: **拿走直接用 `//获取当前时间 getNowTime() { var date = new Date(); //年 ...
- C#表格table时间显示年月日时分秒格式设置
C#表格table时间显示年月日时分秒格式设置 作者:张国军_Suger 开发工具与关键技术:Visual Studio 2015.C#..NET 在做C#项目是遇到的前端表格的时间处理问题,一般都是 ...
- 东八区时间转换为年月日时分秒(2020-10-26T11:34:30Z转换为2020-10-26 11:34:30)
将东八区时间转换为年月日时分秒 //直接上demofunction rTime(date) {var json_date = new Date(date).toJSON();return new Da ...
- python 获取当前时间(年月日时分秒)
python 获取当前时间(年月日时分秒) now_time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
- bat 格式化年月日时分秒
1.调用其他bat,并进行传参: test.bat "..\addon\7z.dll" "..\addon\8z.dll" 2.调用其他bat(新窗口打开其他b ...
- GPS秒转北京时间(年月日时分秒)+ gps 周、周内秒转gps时间戳(单位秒) C++ 代码
目录 一.GPS秒转北京时间(年月日时分秒)- 代码如下: 二.gps
- excel函数-从日期中提取年月日时分秒
excel函数-从日期中提取年月日时分秒 (测试时使用的软件版本:Excel 2016) ps: 图中引号只能是双引号 –over–
- JAVA 获取当前时间(年月日时分秒)
LocalDateTime单独获取年月日和时分秒 LocalDateTime localDateTime = LocalDateTime.now(); localDateTime.format(Dat ...
- js 获取当前日期(年月日时分秒周)
js 获取当前日期(年月日时分秒周) var myDate = new Date(); var myYear = myDate.getFullYear(); // 获取当前年份 var myMonth ...
最新文章
- php zend框架入门,Zend Framework 入门——快速上手
- 设计模式--抽象工厂(Abstract Factory)模式
- java浏览文件夹_一个用java实现简单的文件浏览器
- C++没有调用析构函数
- git 理解 Head指针Branch指针--resetcheckout
- mfc 使打开的窗口至于最顶层_MFC界面开发控件BCG帮助文档——功能区设计器(2)
- AS5047P磁编码器ESP32驱动程序、硬件电路设计、SPI通信时序、逻辑波形分析、注意事项
- Java中List for循环的几种写法种写法总结(推荐)
- 【手写数字识别】基于matlab GUI知识库手写数字识别(写字板+图片)【含Matlab源码 1227期】
- java 删除文件夹及文件夹中的子文件
- 使用前端技术实现静态图片局部流动效果
- 用postman测试post接口的设置步骤,参数为json
- python调用打印机驱动下载_不要驱动,简单粗暴的用树莓派驱动USB打印机
- MAC版SecureCRT+SecureFX破解
- 固态硬盘安装linux系统教程视频,固态硬盘 能安装linux系统吗
- OOAD 3 迭代、进化和敏捷(Iterative,Evolutionary,and Agile)
- 阿里直播平台的架构演进
- OM6621系列国产M4F内核低功耗BLE5.1大内存SoC蓝牙芯片
- XingGAN for Person Image Generation(人体姿势生成笔记)
- java 数组 distinct_去重是distinct还是group by?