zoukankan      html  css  js  c++  java
  • Js获取当前的日期和时间以及时间戳转化为时间

    /**
    	 *获取当前时间
    	 *format=1精确到天
    	 *format=2精确到分
    	*/
    	function getCurrentDate(format) {
    	  var now = new Date();
    	  var year = now.getFullYear(); //得到年份
    	  var month = now.getMonth();//得到月份
    	  var date = now.getDate();//得到日期
    	  var day = now.getDay();//得到周几
    	  var hour = now.getHours();//得到小时
    	  var minu = now.getMinutes();//得到分钟
    	  var sec = now.getSeconds();//得到秒
    	  month = month + 1;
    	  if (month < 10) month = "0" + month;
    	  if (date < 10) date = "0" + date;
    	  if (hour < 10) hour = "0" + hour;
    	  if (minu < 10) minu = "0" + minu;
    	  if (sec < 10) sec = "0" + sec;
    	  var time = "";
    	  //精确到天
    	  if(format==1){
    		time = year + "-" + month + "-" + date;
    	  }
    	  //精确到分
    	  else if(format==2){
    		time = year + "-" + month + "-" + date+ " " + hour + ":" + minu + ":" + sec;
    	  }
    	  return time;
    	}
    	alert(getCurrentDate(2));
    

      

  • 相关阅读:
    Go视频教程
    Mysql常用
    同步Redux
    React跨组件通讯
    React组件通讯
    React
    git生成公钥和私钥
    常用经典算法---希尔排序
    string和c_str()使用时的坑
    腾讯云python网站开发环境搭建
  • 原文地址:https://www.cnblogs.com/ttty/p/10169462.html
Copyright © 2011-2022 走看看