zl程序教程

您现在的位置是:首页 >  前端

当前栏目

javascript实现的距离现在多长时间后的一个格式化的日期

JavaScript日期 实现 一个 格式化 现在 距离 多长时间
2023-06-13 09:14:13 时间
复制代码代码如下:

/**
*
*返回一个距离现在多长时间后的一个格式化的日期,如2009年9月5日14:15:23
*如:现在时间是2009年9月5日14:15:23timeLong=10秒那么返回:2009年9月5日14:15:33
*
*@paraminttimeLong一个
*@paramStringformatStringYYYY-MM-DDhh:mm:ss
*
*/
functiongetOneFormatDate(timeLong,formatString)
{
timeLong=parseInt(timeLong);
timeLong=timeLong*1000;
varmyDate=newDate();
varfutureDate=newDate(parseInt(myDate.getTime())+timeLong);
varyear=futureDate.getYear();
varmonth=futureDate.getMonth();
varday=futureDate.getDate();
varhour=futureDate.getHours();
varminute=futureDate.getMinutes();
varsecond=futureDate.getSeconds();

if(hour<10)
{
hour="0"+hour;
}
if(minute<10)
{
minute="0"+minute;
}
if(second<10)
{
second="0"+second;
}
formatString=formatString.replace("YYYY",year);
formatString=formatString.replace("MM",month);
formatString=formatString.replace("DD",day);
formatString=formatString.replace("hh",hour);
formatString=formatString.replace("mm",minute);
formatString=formatString.replace("ss",second);
returnformatString;
}