0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

時間の設定

Posted at

時間の設定方法

❶現在日時を初期化して代入

let goal = new Date();

❷未来(ゴールの日時を設定)

goal.setHours(23);
goal.setMinites(59);
goal.setsecond1s(59);

:point_up:現在年月日、23時、59分、59分でセット完了(今日の最終日でセットされる)

:warning:

const goal = new Date(2025,4,3)

2025年4月3日を設定

❷functionを設定

function countdown(due){

❷現在日時に初期化

const now = new Date();

❸パラメータdueのミリ秒から、定数nowのミリ秒を引いて、定数restに代入

const rest = due.getTime()- now.getTime();

ミリ秒で算出される

❹定義する

   const sec = Math.floor(rest/1000)%60;
    const min = Math.floor(rest/1000/60)%60;
    const hours = Math.floor(rest/1000/60/60)%24;
    const days = Math.floor(rest/1000/60/60/24);

❺配列準備する

const count = [days,hours, min,sec];
return count;

呼び出し元にリターンする

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?