Home > Web Front-end > JS Tutorial > JavaScript implements a formatted date_time and date how long it will be from now

JavaScript implements a formatted date_time and date how long it will be from now

WBOY
Release: 2016-05-16 18:43:04
Original
1104 people have browsed it
复制代码 代码如下:

/**
*
* Returns a formatted date how long it is from now, such as September 5, 2009 14:15:23
* For example: the current time is September 5, 2009 14:15:23 timeLong=10 seconds then return: September 5, 2009 14:15:33
*
* @param int timeLong a
* @param String formatString YYYY-MM-DD hh :mm:ss
*
*/
function getOneFormatDate(timeLong,formatString)
{
timeLong=parseInt(timeLong);
timeLong=timeLong*1000;
var myDate=new Date();
var futureDate=new Date(parseInt(myDate.getTime()) timeLong);
var year=futureDate.getYear();
var month=futureDate.getMonth();
var day=futureDate.getDate();
var hour=futureDate.getHours();
var minute=futureDate.getMinutes();
var second=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);
return formatString;
}
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template