Commit 5cf8525e authored by 13841799530's avatar 13841799530

封装时间戳

解润东
20211110
parent fe551eb6
Pipeline #7075 passed with stage
in 10 seconds
export default {
//转换日期格式
//time : 要转换的时间
//type : DT1 转换为 2019-01-01 8:12:42格式
//type : DT2 转换为 2019-01-01格式
//type : DT3 转换为 2019/01/01 8:12:42格式
//type : DT4 转换为 2019/01/01格式
//type : DT5 转换为 时间戳格式
//type : DT6 转换为 2019年01月01日 8时12分42秒
//type : DT7 转换为 2019年01月01日
//zero : 时分秒是否补零(2000-01-01 08:02:06)
//num : 要加的天数,正数为加,负数为减,不加不减就不用传
timestampToTime (time,type,zero,num) {
if(!time){return ''}
try{
var date = new Date(time)
if(num&&typeof parseInt(num)=="number"){
date = new Date(new Date(time).getTime()+num*60*60*24*1000)//时间戳以毫秒为单位,也可用其他日期格式
}
let yy = date.getFullYear();//年
let mm = date.getMonth()+1;//月
let dd = date.getDate();//日
let hh = date.getHours();//小时
let mf = date.getMinutes()<10 ? '0'+date.getMinutes() : date.getMinutes();//分钟
let ss = date.getSeconds()<10 ? '0'+date.getSeconds() : date.getSeconds();//秒
if(zero){
if(mm<10){mm='0'+mm}
if(dd<10){dd='0'+dd}
if(hh<10){hh='0'+hh}
}
if(type=="DT1"){
return yy+'-'+mm+'-'+dd+' '+hh+':'+mf+':'+ss;//yyyy-mm-dd hh:mf:ss
}else if(type=="DT2"){
return yy+'-'+mm+'-'+dd;//yyyy-mm-dd
}else if(type=="DT3"){
return yy+'/'+mm+'/'+dd+' '+hh+':'+mf+':'+ss;//yyyy/mm/dd hh:mf:ss
}else if(type=="DT4"){
return yy+'-'+mm+'-'+dd;//yyyy/mm/dd
}else if(type=="DT5"){
return date.getTime();//时间戳 秒数
}else if(type=="DT6"){
return yy+''+mm+''+dd+''+hh+''+mf+''+ss+'';//yyyy年mm月dd日 hh时mf分ss秒
}else if(type=="DT7"){
return yy+''+mm+''+dd+'';//yyyy年mm月dd日
}else if(type=="DT8"){
return yy+'-'+mm+'-'+dd+' '+'00'+':'+'00'+':'+'00';//yyyy-mm-dd hh:mf:ss
}
}catch(e){
console.log("timestampToTime Error");return ""
}
},
}
\ No newline at end of file
......@@ -12,6 +12,7 @@ import md5 from 'js-md5';
import App from './App.vue'
import router from './router'
import store from './store'
import util from './api/util.js'
import './permission'
import Cookies from 'js-cookie'
import { prefix } from '@/common/js/utils'
......@@ -20,6 +21,7 @@ Step, Steps } from 'vant'
import 'lib-flexible/flexible'
import vueEsign from 'vue-esign'
Vue.use(vueEsign)
Vue.prototype.util = util
Vue.use(Divider).use(Popup).use(Overlay).use(Loading).use(Dialog).use(Toast).use(ContactCard).use(Form).use(AddressEdit).use(AddressList).use(Field).use(CellGroup).use(Cell).use(SwipeCell).use(Icon).use(Stepper).use(Card).use(Button).use(Swipe).use(SwipeItem).use(PullRefresh).use(List).use(Tab).use(Tabs).use(GoodsAction).use(GoodsActionIcon).use(GoodsActionButton).use(SubmitBar).use(Checkbox).use(CheckboxGroup).use(Search).use(Picker).use(Uploader).use(Notify)
.use(ContactList).use(Calendar).use(Radio).use(RadioGroup).use(Tag).use(Tabbar).use(TabbarItem).use(Sticky)
.use(Grid).use(GridItem).use(Skeleton).use(Col).use(Row).use(VanImage).use(Badge).use(NoticeBar).use(DatetimePicker).use(Step).use(Steps)
......
......@@ -293,7 +293,7 @@ export default {
},
/* 时间戳转换 */
onConfirm(date) {
this.value = `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()} ${date.getHours()+':00:00'}`;
this.value = this.util.timestampToTime(date,'DT1',true)
this.showCalendar = false;
},
//日期输入框点击事件
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment