时间戳转换,时间钟表

博客主要介绍了两方面内容,一是时间戳转换,以种植时间为例,给出开始种植时间和时长,需求是获取结束种植时间,并提及转换时的格式要求;二是时间钟表显示,实现每隔一秒实时变动,还给出了相关参考链接。
一·时间戳转换
start_time开始种植时间: 2019-03-08
plant_circle种植时长: 365
需求:我想拿到结束种植时间 _________ 应该是2020-03-07
/**
后台传过来的数据:

	start_time开始种植时间: 2019-03-08
	plant_circle种植时长: 365
	需求:我想拿到结束种植时间 _________ 应该是2020-03-07
**/
   sDate(start_time,plant_circle) {
       let ss = 24 * 60 * 60 * 1000; //一天的毫秒数86400
       let timestamp = new Date(start_time).getTime(); //获取相关时间戳
       let date = new Date(ss * plant_circle + timestamp) //加上n天的国际标准日期
       let year=date.getFullYear();
       let month= date.getMonth()+1<10 ? "0"+(date.getMonth()+1) : date.getMonth()+1;
       let day=date.getDate()<10 ? "0"+date.getDate() : date.getDate();
       return year + '-' + month + '-' + day ; //拼接成我们需要的格式返回
   },

方法二:
	//时间转换—— js 
	15764628200002019-12-16 10:30:20
	
    zhDate(years){
      var nowXz = new Date(Number(years))  //时间戳格式——数字类型
      let year=nowXz.getFullYear();
      let month= nowXz.getMonth()+1<10 ? "0"+(nowXz.getMonth()+1) : nowXz.getMonth()+1;
      let day=nowXz.getDate()<10 ? "0"+nowXz.getDate() : nowXz.getDate();
    return year + '-' + month + '-' + day ;
    },

  //日期转时间戳  
  2019-12-16 10:30:20  ==> 1576462820000
  
  let timeinfo = '2019-12-16 10:30:20';
  let timeTT = new Date(timeinfo); //转化标准日期格式
  timeTT = timeTT.getTime();    //将日期格式转换成时间戳:

在这里插入图片描述
new Date(timeinfo) ==>> ****** timeinfo必须是字符窜 不然会转不了******
方法二:后台转入格式在这里插入图片描述
最终结果——2019-10-21

.
二· 时间钟表 显示
每隔一秒时间走一次 实时变动

每隔一秒时间走一次

//时间
    setInterval(updateTime, 1000);
    updateTime();
	  function updateTime() {
	      var date = new Date();
	      this.year = date.getFullYear();
	      this.month = date.getMonth() + 1;
	      this.date = date.getDate();
	      this.day = new Array("星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六")[date.getDay()];
	      this.hour = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
	      this.minute = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
	      this.second = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
	      var currentTime =  this.year + "." + this.month + "." + this.date + " " + this.day+ " "+this.hour + ":" + this.minute + ":" + this.second  ;
	      $("#date").html(currentTime);
	  }

https://www.cnblogs.com/willingtolove/p/9544877.html
时间转时间戳
时间戳转时间

拿着 不谢 请叫我“锤” 谢谢!!!
表盘式时钟,并显import java.awt.*; import java.awt.event.*; import javax.swing.*; import sun.util.calendar.Gregorian; import java.util.Calendar; import java.util.GregorianCalendar; public class Clock extends JFrame implements ActionListener{ int x, y, x0, y0, r, h, olds_x, olds_y, oldm_x, oldm_y, oldh_x, oldh_y, ss,mm,hh,old_m,old_h,ang; final double RAD = Math.PI/180; public Clock(){ super("Java时钟"); setDefaultCloseOperation(3); Image image = getToolkit().getImage("clock.gif"); setIconImage(image); setSize(200,200); setBackground(Color.black); setLocation(300,150); setResizable(false); show(); int delay = 1000; //创建一个监听事件 ActionListener drawClock = new ActionListener(){ public void actionPerformed(ActionEvent evt){ repaint(); } }; //创建一个时间计数器,每一秒触发一次 new Timer(delay,drawClock).start(); } //实现ActionListener接口必须实现的方法 public void actionPerformed(ActionEvent evt){} //绘制图形 public void paint(Graphics g){ Graphics2D g2D = (Graphics2D)g; Insets insets = getInsets(); int L = insets.left/2, T = insets.top/2; h = getSize().height; g.setColor(Color.white); //画圆 g2D.setStroke(new BasicStroke(4.0f)); g.drawOval(L+40, T+40, h-80, h-80); r = h/2 - 40; x0 = 40 + r - 5 + L; y0 = 40 + r - 5 - T; ang = 60; //绘制时钟上的12个字 for(int i = 1;i <= 12;i ++){ x = (int)((r+10)*Math.cos(RAD*ang)+x0); y = (int)((r+10)*Math.sin(RAD*ang)+y0); g.drawString(""+i, x, h-y); ang -=30; } //获得现在的时间 Calendar now = new GregorianCalendar(); int nowh = now.get(Calendar.HOUR_OF_DAY); int nowm = now.get(Calendar.MINUTE); int nows = now.get(Calendar.SECOND); String st; if(nowh < 10)st = "0"+nowh; else st = ""+nowh; if(nowm<10)st += ":0"+nowm; else st += ":"+nowm; if(nows<10)st += ":0"+nows; else st += ":"+nows; //在窗体上显示时间 g.setColor(Color.pink); g.fillRect(L, T, 50, 28); g.setColor(Color.blue); g.drawString(st,L+2,T+26); //计算时间与度数的关系 ss = 90 - nows*6; mm = 90 - nowm*
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值