blog

一般的な時間フォーマットの方法

自分で使うための時間フォーマット法、小さな機能のためにパッケージファイルを導入するのは好きではありません。...

Jul 27, 2020 · 2 min. read

小さな機能のためにパッケージファイルを導入するのは好きではありません。

//時差を計算してカウントダウンをする
export function initTime (actTime, currentTime) {
 let activitytimer = +new Date(actTime);
 let newTime = currentTime;
 let difftime = activitytimer - newTime;
 if (difftime >= 0) {
 let days =
 Math.floor(difftime /  / 24) > 9
 ? Math.floor(difftime /  / 24)
 : '0' + Math.floor(difftime /  / 24);
 let houres =
 Math.floor(difftime /  % 24) > 9
 ? Math.floor(difftime /  % 24)
 : '0' + Math.floor(difftime /  % 24);
 let minutes =
 Math.floor((difftime / ) % 60) > 9
 ? Math.floor((difftime / ) % 60)
 : '0' + Math.floor((difftime / ) % 60);
 let seconds =
 Math.floor((difftime / 1000) % 60) > 9
 ? Math.floor((difftime / 1000) % 60)
 : '0' + Math.floor((difftime / 1000) % 60);
 let countTimes = days + '天' + houres + ':' + minutes + ':' + seconds;
 return countTimes;
 } else {
 return ':00';
 }
}
//年-月-日 時 分 秒
export function formatTime (times) {
 let time = new Date(times * 1000)
 let year = time.getFullYear()
 let mouth = time.getMonth() + 1 < 10 ? '0' + (time.getMonth() + 1) : time.getMonth() + 1
 let day = time.getDate() < 10 ? '0' + time.getDate() : time.getDate()
 let hours = time.getHours() < 10 ? '0' + time.getHours() : time.getHours()
 let minutes = time.getMinutes() < 10 ? '0' + time.getMinutes() : time.getMinutes()
 let seconds = time.getSeconds() < 10 ? '0' + time.getSeconds() : time.getSeconds()
 let str = `${year}-${mouth}-${day} ${hours}:${minutes}:${seconds}`
 return str
}
// タイムスタンプの配列を返す
export function formatTimeArr (times) {
 let time = times.map(v => (+new Date(v)) / 1000)
 return time
}
// タイムスタンプを返す
export function formatTimesingle (times) {
 let time = (+new Date(times)) / 1000
 return time
}
Read next

HTTPリクエストとレスポンス

リクエストを送信する方法クロームアドレスバーcurlコマンドNode.jsに応答する方法別のhttpモジュールは、ノートを表示するために行うことができますこれらのコードは、サーバーコード、パス上のサーバーのバージョンではありませんクエリパラメータpath/xqueryは、クエリパラメータオブジェクト形式です。

Jul 24, 2020 · 2 min read

URL入門

Jul 22, 2020 · 3 min read

質問02.06.

Jul 19, 2020 · 1 min read

問題01.08. ゼロマトリックス

Jul 18, 2020 · 1 min read