uipath如何获取当日日期_JS 取当前日期、时间的代码 - \(^o^)/~ - CSDN博客

JS 取当前日期、时间的代码 收藏

1.JS 取当前日期、时间的代码?

--------------------------------------------------------------------------------

view plaincopy to clipboardprint?

2.如何用js得到 yyyy-mm-dd格式的当前日期?

--------------------------------------------------------------------------------

view plaincopy to clipboardprint?

function   appendZero(s){return   ("00"+   s).substr((s+"").length);}     //补0函数

var   d   =   new   Date();

alert(d.getFullYear()   +   "-"   +   appendZero(d.getMonth()   +   1)   +   "-"   +   appendZero(d.getDate()));

function   appendZero(s){return   ("00"+   s).substr((s+"").length);}     //补0函数

var   d   =   new   Date();

alert(d.getFullYear()   +   "-"   +   appendZero(d.getMonth()   +   1)   +   "-"   +   appendZero(d.getDate()));

3.javascript 获得指定日期的临近日期的方法

view plaincopy to clipboardprint?

//取得日期字符串,返回YYYY-MM-DD

function getDate(date)

{

var thisYear = date.getYear();

var thisMonth = date.getMonth() + 1;

//如果月份长度是一位则前面补0

if(thisMonth<10) thisMonth = "0" + thisMonth;

var thisDay = date.getDate();

//如果天的长度是一位则前面补0

if(thisDay<10) thisDay = "0" + thisDay;

return thisYear + "-" + thisMonth + "-" + thisDay;

}

//取得日期时间字符串,返回YYYY-MM-DD HH:mm:SS

function getDateTime(date)

{

var thisYear = date.getYear();

var thisMonth = date.getMonth() + 1;

//如果月份长度是一位则前面补0

if(thisMonth<10) thisMonth = "0" + thisMonth;

var thisDay = date.getDate();

//如果天的长度是一位则前面补0

if(thisDay<10) thisDay = "0" + thisDay;

var thisHour = date.getHours();

//如果小时长度是一位则前面补0

if(thisHour<10) thisHour = "0" + thisHour;

var thisMinute = date.getMinutes();

//如果分钟长度是一位则前面补0

if(thisMinute<10) thisMinute = "0" + thisMinute;

var thisSecond = date.getSeconds();

//如果分钟长度是一位则前面补0

if(thisSecond<10) thisSecond = "0" + thisSecond;

return thisYear + "-" + thisMonth + "-" + thisDay + " " + thisHour + ":" + thisMinute + ":" + thisSecond;

}

//根据日期字符串生成日期对象,日期字符串格式为YYYY-MM-DD

function setDate(strDate)

{

var aDate = strDate.split("-");

return new Date(aDate[0],aDate[1]-1,aDate[2]);

}

//获得指定日期的临近日期

//strDate:指定的日期,格式为yyyy-mm-dd  nDay:与指定日期相邻的天数 1为明天 -1为昨天

function getNearDay(strDate,nDay)

{

try

{

var oDate = setDate(strDate);

var newDate = new Date(oDate.valueOf() + nDay*24*60*60*1000);

return getDate(newDate);

}

catch(ex)

{

return "error";

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值