Front-end: Vue +elementUI, back-end: strapi

1, Convert Chinese time to UTC format

The front end uses the time selection box of elementUI

<el-date-picker v-model="selectDate" type="daterange" range-separator=" to "start-placeholder=" start date" Margin-right: 1px; margin-right: 1px; margin-right: 1px; margin-right: 1px

Where selectDate :[]

The console print output is Chinese standard time, and the background needs UTC format



Js code:

start = new Date(n[0]).toISOString()
end = new Date(n[1]).toISOString()

Conversion results:

"THU JUL 01 2021 00:00:00 GMT+0800 (China Standard Time)" "2021-06-30T16:00:00.000Z"

2, change the Chinese time to YYYY-MM-DD H-M-S

dataTransform(time){
      var date =  new Date(time),
      year = date.getFullYear(),
      month = date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1,
      day = date.getDate() < 10 ? '0' + date.getDate() : date.getDate(),
      hour = date.getHours() < 10 ? '0' + date.getHours() : date.getHours(),
      minute = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes(),
      second = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds();
      return year + '-' + month + '-' + day + '  ' + hour + ':' + minute + ':' + second;
}

Also: ElementUI’s time selection box supports conversion formats without using JS conversion. value-format=”yyyy-MM-dd”

<el-date-picker v-model="selectDate" type="daterange" range-separator=" to "start-placeholder=" start date" Align =" left "style="margin-right:10px" style="margin-right:10px" style="margin-right:10px" style="margin-right:10px" style="margin-right:10px