blog

JS時刻はyyyy-MM-dd hh:mm:ssでフォーマットされる。

##Call the way...

May 10, 2020 · 2 min. read
/** * Parse the time to string * @param {(Object|string|number)} time * @param {string} cFormat * @returns {string | null} */ export function parseTime(time, cFormat) { if (arguments.length === 0) { return null } const format = cFormat || '{y}-{m}-{d} {h}:{i}:{s}' let date if (typeof time === 'object') { date = time } else { if ((typeof time === 'string') && (/^[0-9]+$/.test(time))) { time = parseInt(time) } if ((typeof time === 'number') && (time.toString().length === 10)) { time = time * 1000 } date = new Date(time) } const formatObj = { y: date.getFullYear(), m: date.getMonth() + 1, d: date.getDate(), h: date.getHours(), i: date.getMinutes(), s: date.getSeconds(), a: date.getDay() } const time_str = format.replace(/{([ymdhisa])+}/g, (result, key) => { const value = formatObj[key] // Note: getDay() returns 0 on Sunday if (key === 'a') { return [' ', ' ', ' ', ' ', ' ', ' ', ' '][value ] } return value.toString().padStart(2, '0') }) return time_str } /** * Parse the time to string * @param {(Object|string|number)} date * @param {string} format * @returns {string | null} */ export function dateFormat (date, format) { date = new Date(date); date.setHours(date.getHours()-14); var o = { 'M+' : date.getMonth() + 1, //month 'd+' : date.getDate(), //day 'H+' : date.getHours(), //hour 'm+' : date.getMinutes(), //minute 's+' : date.getSeconds(), //second 'q+' : Math.floor((date.getMonth() + 3) / 3), //quarter 'S' : date.getMilliseconds() //millisecond }; if (/(y+)/.test(format)) format = format.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length)); for (var k in o) if (new RegExp('(' + k + ')').test(format)){ format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ('00' + o[k]).substr(('' + o[k]).length)); } return format; }

## ♪ ♪ Calling the way

 /**
 *標準データのみサポート
 */
item.createTime = dateFormat(item.createTime,'yyyy-MM-dd HH:mm:ss')
item.createTime = parseTime('','{y}-{m}-{d} {h}:{i}:{s}')
item.createTime = parseTime('T.','{y}-{m}-{d} {h}:{i}:{s}')
Read next

[最初にしなければならないことは、データを回復するためにビンログを使用することである。

まとめると、binlogは記録されたSQL文に従ってデータを復元したり、ちょっとした修理をしたり、主にバックアップに頼ったりするのにしか使えません。

May 8, 2020 · 2 min read