TS格式化时间(适用于标准时间、时间戳等)
TS格式化时间(适用于标准时间、时间戳等)
/*** 时间工具类*/
export class DateUtil {/*** 格式化时间* 调用formatDate(strDate, 'yyyy-MM-dd');* @param strDate(中国标准时间、时间戳等)* @param strFormat(返回格式)*/public formatDate(strDate: any, strFormat?: any){if (!strDate){ return; }if (!strFormat){ strFormat = 'yyyy-MM-dd'; }switch (typeof strDate) {case 'string':strDate = new Date(strDate.replace(/-/, '/'));break;case 'number':strDate = new Date(strDate);break;}if (strDate instanceof Date){const dict: any = {yyyy: strDate.getFullYear(),M: strDate.getMonth() + 1,d: strDate.getDate(),H: strDate.getHours(),m: strDate.getMinutes(),s: strDate.getSeconds(),MM: ('' + (strDate.getMonth() + 101)).substr(1),dd: ('' + (strDate.getDate() + 100)).substr(1),HH: ('' + (strDate.getHours() + 100)).substr(1),mm: ('' + (strDate.getMinutes() + 100)).substr(1),ss: ('' + (strDate.getSeconds() + 100)).substr(1),};return strFormat.replace(/(yyyy|MM?|dd?|HH?|mm?|ss?)/g, function () {return dict[arguments[0]];});}}
}
TS格式化时间(适用于标准时间、时间戳等)相关推荐
- 格式化时间转化为时间戳
const std::string date("2022-12-12 00:00:00"); std::regex reg("(\\d+)-(\\d+)-(\\d+)(\ ...
- 格式化时间转换时间戳
format.format(date) -->转换为格式化时间 format.parse(String)-->格式化时间转化为时间戳 format.parse(String,ParsePo ...
- Go语言获取当天、昨天、明天、某天0点时间戳以及格式化时间
获取当前时间 到 明天0点整的时间差的秒级时间戳的字符串形式 func GetTimeDifference() string {nowTime := time.Now()// 当天秒级时间戳nowTi ...
- python unix时间戳格式化输出_python正常时间和unix时间戳相互转换的方法
本文实例讲述了python正常时间和unix时间戳相互转换的方法.分享给大家供大家参考.具体分析如下: 这段代码可以用来转换常规时间格式为unix时间戳,也可以将unix时间戳转换回来, 例如:133 ...
- Java 时间处理(格式解释、格式化时间、获取当前时间、获取年份、月份等、时间戳转换成时间)
日期和时间模式(注意大小写,代表的含义是不同的): yyyy:年 MM:月 dd:日 hh:1~12小时制(1-12) HH:24小时制(0-23) mm:分 ss:秒 S:毫秒 E:星期几 D:一年 ...
- python --格式化时间转时间戳(互转)
import time import datetimeclass TimesType(object):'''时间格式互转'''def __new__(cls, *args, **kwargs):''' ...
- 2 时间格式化_关于Python时间戳是什么讲解
时间戳是指格林威治时间自1970年1月1日(00:00:00 GMT)至当前时间的总秒数.它也被称为Unix时间戳(Unix Timestamp). 百度百科对时间戳的定义是,一个能表示一份数据在某个 ...
- php中时间戳转换为毫秒以及格式化时间
前言 有时候需要对时间戳进行操作,比如获取13位毫秒级的时间戳或者对时间戳进行格式化时间. /*** 转化时间为毫秒时间戳* @param int|string $time 时间戳|日期* @retu ...
- vue使用过滤器将时间戳格式化时间
使用moment插件格式化.如果写成方法的话,则每个页面都要写这个方法.所以还有一种,定义全局过滤器,将时间戳格式化 在main.js中定义 Vue.filter('dateFormat', (dat ...
最新文章
- 挡不住的AI成熟趋势
- OpenCV2.4.9 For Android + Android Studio (with gradle)配置教程
- Redis cluster日常管理【一】
- 2009年上半年网络工程师考试下午试卷参考答案(二)
- php新闻删除功能设计,php原生开发新闻站之删除新闻
- spring 使用XML配置开发Spring AOP
- Java项目的命名规范
- 盘点目前初学者适合用的C语言编程工具!C语言初学者必看!
- json-server 模拟数据
- 在Java中构建响应式微服务系统——第三章 构建响应式微服务
- mix2s android p,待遇堪比“亲儿子” 小米MIX 2s迎来Android P升级
- win10怎样获得计算机管理员权限,详细教你获取win10管理员权限
- 数据可视化第3篇:安装linux操作系统5系列
- 学习笔记 | c++中四种类型cast(强制)转换
- typescript 提示 Object is possibly null
- CUDA入门和网络加速学习(三)
- 616 给字符串添加加粗标签
- 黑客攻击五种手段,其实要避免也不难,终究离不开骗术
- 三菱PLC程序三菱Q系列案例三菱plc大型自动化程序生产线程序
- SD卡误删了照片怎么恢复?照片恢复教程分享