【Vue】时间戳转换为年月日 格式为 yyyy-MM-dd hh:mm js转换时间戳 时间戳转换为年月日 Fri Apr 01 2022 00:00:00 GMT+0800 (中国标准时间)转换
Vue中将时间戳转换为年月日
用法
时间戳转换为年月日 yyyy-MM-dd hh:mm
用法1: formatDate(new Date(val * 1000), ‘yyyy年MM月dd日 hh:mm’)
val为10位数时间戳 使用是13位,大概率获取的是10位
用法2: formatDate(date, ‘yyyy年MM月dd日 hh:mm’)
date为 Tue Oct 25 2022 09:44:28 GMT+0800 (GMT+08:00)
1657715711147
这是时间戳
let date = new Date(时间戳)
let time = formatDate(date, 'yyyy-MM-dd hh:mm')
//time = 2022-06-01 00:00
把对应时间戳的变量填进去,
一定是13位时间戳, 如果不是 就乘1000 要把毫秒数算上
方法
写在vue的methods里面,如果不是在vue里面用的话
就把里面的 this 删除
formatDate(date, fmt) {if (/(y+)/.test(fmt)) {fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length))
}let o = { 'M+': date.getMonth() + 1,'d+': date.getDate(),'h+': date.getHours(),'m+': date.getMinutes(),'s+': date.getSeconds()}for (let k in o) {if (new RegExp(`(${k})`).test(fmt)) {let str = o[k] + ''fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? str : this.padLeftZero(str))}}return fmt
},
padLeftZero(str) {return ('00' + str).substr(str.length)
}
这是方法,接下来看怎么调用
let date = new Date(时间戳)
formatDate(date, ‘yyyy-MM-dd hh:mm’)
这是执行方法
public static void main(final String[] args) { final SimpleDateFormat sdFormat=new SimpleDateFormat( ... 普通filter <view class="date">{{date | formatDate}} </view> filters: {formatDate ... new Date(2019-05-31T06:41:32Z) C# 中的年月日时分秒 yyyy MM dd HH mm ss 其中大小写含义不同,不能混用 年:yyyy 月:MM 日:dd(1-31) DD(0-365) 时:hh:12小时制 HH:24小时制 ... 使用kettle出现 couldn't convert string [...] to a date using format [yyyy/MM/dd HH:mm:ss.SSS] 试了各种方法,最后发 ... 苹果手机ios系统居然特喵的 不支持日期yyyy-MM-dd HH:mm:ss.ms, 只支持yyyy/MM/dd HH:mm:ss 我只能用 .replace(/\-/g,'\/'); 来替换掉了, ... 转换yyyy-MM-dd HH:mm:ss( DateUtil) import java.text.SimpleDateFormat; import java.util.Date; import ja ... 类似Thu May 18 2017 00:00:00 GMT+0800 (中国标准时间)格式的时间转换成2017/05/18 或取其时分秒,方法如下: /** * @param datdString ... 转换yyyy-MM-dd HH:mm:ss( DateUtil) import java.text.SimpleDateFormat; import java.util.Date; import ja ...【Vue】时间戳转换为年月日 格式为 yyyy-MM-dd hh:mm js转换时间戳 时间戳转换为年月日 Fri Apr 01 2022 00:00:00 GMT+0800 (中国标准时间)转换相关推荐
最新文章
热门文章