js获取当前当前年月日时分秒,以及获取年月日(无时分秒),详情见补充!

js获取当前当前年月日时分秒,以及获取年月日(无时分秒),详情见补充!,第1张

1、新建一个HTML文件,命名为testhtml。

2、在JS中使用new Date()获得当前系统的时间,并将其保存在变量d中。当前时间的年份使用getYear()方法从变量d中获得。

3、使用new Date()获得当前系统的时间,并将其保存在变量d中。当前时间的月份使用getMonth()方法从变量d中获得。

4、在JS中使用new Date()获得当前系统的时间,并将其保存在变量d中。当前时间的日期使用getDate()方法从变量d中获得。

5、在JS中使用new Date()获得当前系统的时间,并将其保存在变量d中。当前时间的小时使用getHours()方法从变量d中获得。

6、在JS中使用new Date()获得当前系统的时间,并将其保存在变量d中。当前时间的秒数使用getSeconds()方法从变量d中获得。

7、就完成了。

写一个方法:

1接收传递进来的时间参数

2用time函数得到当前系统时间,和传递进来的参数对比

3执行对比判断后的相应的功能:关闭或者什么也不做

在页面load时设定多长时间执行一次这个方法

setInterval('方法名',1000);

function init(){

  clock();

  setInterval(clock,1000);

}

function clock(){

  var now = new Date();

  var ctx = documentgetElementById('canvas')getContext('2d');

  ctxsave();

  ctxclearRect(0,0,150,150);

  ctxtranslate(75,75);

  ctxscale(04,04);

  ctxrotate(-MathPI/2);

  ctxstrokeStyle = "black";

  ctxfillStyle = "white";

  ctxlineWidth = 8;

  ctxlineCap = "round";

  // Hour marks

  ctxsave();

  for (var i=0;i<12;i++){

    ctxbeginPath();

    ctxrotate(MathPI/6);

    ctxmoveTo(100,0);

    ctxlineTo(120,0);

    ctxstroke();

  }

  ctxrestore();

  // Minute marks

  ctxsave();

  ctxlineWidth = 5;

  for (i=0;i<60;i++){

    if (i%5!=0) {

      ctxbeginPath();

      ctxmoveTo(117,0);

      ctxlineTo(120,0);

      ctxstroke();

    }

    ctxrotate(MathPI/30);

  }

  ctxrestore();

  

  var sec = nowgetSeconds();

  var min = nowgetMinutes();

  var hr  = nowgetHours();

  hr = hr>=12  hr-12 : hr;

  ctxfillStyle = "black";

  // write Hours

  ctxsave();

  ctxrotate( hr(MathPI/6) + (MathPI/360)min + (MathPI/21600)sec )

  ctxlineWidth = 14;

  ctxbeginPath();

  ctxmoveTo(-20,0);

  ctxlineTo(80,0);

  ctxstroke();

  ctxrestore();

  // write Minutes

  ctxsave();

  ctxrotate( (MathPI/30)min + (MathPI/1800)sec )

  ctxlineWidth = 10;

  ctxbeginPath();

  ctxmoveTo(-28,0);

  ctxlineTo(112,0);

  ctxstroke();

  ctxrestore();

  

  // Write seconds

  ctxsave();

  ctxrotate(sec  MathPI/30);

  ctxstrokeStyle = "#D40000";

  ctxfillStyle = "#D40000";

  ctxlineWidth = 6;

  ctxbeginPath();

  ctxmoveTo(-30,0);

  ctxlineTo(83,0);

  ctxstroke();

  ctxbeginPath();

  ctxarc(0,0,10,0,MathPI2,true);

  ctxfill();

  ctxbeginPath();

  ctxarc(95,0,10,0,MathPI2,true);

  ctxstroke();

  ctxfillStyle = "#555";

  ctxarc(0,0,3,0,MathPI2,true);

  ctxfill();

  ctxrestore();

  ctxbeginPath();

  ctxlineWidth = 14;

  ctxstrokeStyle = '#325FA2';

  ctxarc(0,0,142,0,MathPI2,true);

  ctxstroke();

  ctxrestore();

}

以上就是关于js获取当前当前年月日时分秒,以及获取年月日(无时分秒),详情见补充!全部的内容,包括:js获取当前当前年月日时分秒,以及获取年月日(无时分秒),详情见补充!、JS循环获取当前系统时间、如何用javascript实现一个时钟等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/web/9526935.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-29
下一篇2023-04-29

发表评论

登录后才能评论

评论列表(0条)

    保存