Skip to content

Commit

Permalink
feat: change date string format "yyyy-MM-dd hh:mm:ss" with local time…
Browse files Browse the repository at this point in the history
… zone
  • Loading branch information
DG-Wangtao committed Mar 6, 2020
1 parent fbe6d18 commit 0983166
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "timestamp-convert",
"version": "1.0.5",
"version": "1.0.6",
"description": "A Electron application convert timestamp to datetime loacle string",
"repository": "github:WaylandWong/timestamp-convert",
"main": "./src/main.js",
Expand Down
26 changes: 25 additions & 1 deletion src/script/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,28 @@
'use-strict';
function padding(length, num){
return (Array(length).join("0") + num).slice(-length);
}
Date.prototype.format = function(fmt) {
var o = {
"M+" : this.getMonth()+1, //月份
"d+" : this.getDate(), //日
"h+" : this.getHours(), //小时
"m+" : this.getMinutes(), //分
"s+" : this.getSeconds(), //秒
"q+" : Math.floor((this.getMonth()+3)/3), //季度
"S" : this.getMilliseconds() //毫秒
};
if(/(y+)/.test(fmt)) {
fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));
}
for(var k in o) {
if(new RegExp("("+ k +")").test(fmt)){
fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));
}
}
return fmt;
}


window.ipcRenderer.on('show', (event, message) => {
if (document.activeElement.id !== 'output') {
Expand Down Expand Up @@ -140,7 +164,7 @@ function uuid(version) {
*/
function getTimeStr(timestamp) {
const unixTimestamp = new Date(timestamp);
return unixTimestamp.toISOString();
return unixTimestamp.format("yyyy-MM-dd hh:mm:ss")
}

document.onkeyup = keyUp;
Expand Down

0 comments on commit 0983166

Please sign in to comment.