微信小程序new Date()转换时间异常问题

2021-03-06

2587 0 0

微信小程序苹果手机页面上显示时间异常,安卓机正常问题 image 错误代码

1var date = '2021-03-06 17:00:00' 2var dateTime = new Date(date)

正确代码

1var date = '2021-03-06 17:00:00' 2var dateTime = new Date(date.replace(/-/g,'/'))

时间戳转换字符串方法

1const formatTime = date => { 2 const year = date.getFullYear() 3 const month = date.getMonth() + 1 4 const day = date.getDate() 5 const hour = date.getHours() 6 const minute = date.getMinutes() 7 const second = date.getSeconds() 8 9 return [year, month, day].map(formatNumber).join('-') + ' ' + [hour, minute, second].map(formatNumber).join(':') 10} 11 12const formatNumber = n => { 13 n = n.toString() 14 return n[1] ? n : '0' + n 15} 16 17function isBlank(str){ 18 if (Object.prototype.toString.call(str) ==='[object Undefined]'){//空 19 return true 20 } else if ( 21 Object.prototype.toString.call(str) === '[object String]' || 22 Object.prototype.toString.call(str) === '[object Array]') { //字条串或数组 23 return str.length==0?true:false 24 } else if (Object.prototype.toString.call(str) === '[object Object]') { 25 return JSON.stringify(str)=='{}'?true:false 26 }else{ 27 return true 28 } 29} 30 31module.exports = { 32 formatTime: formatTime, 33 isBlank: isBlank 34}
点赞
收藏

评论区

加载中...

相关推荐

MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1

文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s

Oracle 分组与拼接字符串同时使用

SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(

MySQL部分从库上面因为大量的临时表tmp_table造成慢查询

背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_

手写Java HashMap源码

HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22

Java获得今日零时零分零秒的时间(Date型)

publicDatezeroTime()throwsParseException{    DatetimenewDate();    SimpleDateFormatsimpnewSimpleDateFormat("yyyyMMdd00:00:00");    SimpleDateFormatsimp2newS

Python之time模块的时间戳、时间字符串格式化与转换

Python处理时间和时间戳的内置模块就有time,和datetime两个,本文先说time模块。关于时间戳的几个概念时间戳,根据1970年1月1日00:00:00开始按秒计算的偏移量。时间元组(struct_time),包含9个元素。 time.struct_time(tm_y