javascript实现的距离现在多长时间后的一个格式化的日期
作者:bea
代码如下: /** * * 返回一个距离现在多长时间后的一个格式化的日期,如2009年9月5日 14:15:23 * 如:现在时间是2009年9月5日 14:15:23 timeLong=10秒 那么返回:2009年9月5日 14:15:33 * * @param int timeLong 一个 * @param String formatString YYYY-MM-DD hh:mm:ss * */ function getOneFormatDate(
代码如下:
/**
*
* 返回一个距离现在多长时间后的一个格式化的日期,如2009年9月5日 14:15:23
* 如:现在时间是2009年9月5日 14:15:23 timeLong=10秒 那么返回:2009年9月5日 14:15:33
*
* @param int timeLong 一个
* @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;
}
有用 | 无用
猜你喜欢
您可能感兴趣的文章:
- js 函数的执行环境和作用域链的深入解析
- 提高网站性能之 如何对待JavaScript
- JavaScript Sort 表格排序
- DOM 脚本编程中的兄弟节点
- javascript GUID生成器实现代码
- JavaScript中的JSON 中文版翻译
- json 实例详细说明教程
- json 入门基础教程 推荐
- jquery text()要注意啦
- CCPry JS类库 代码
- Iframe 自适应高度并实时监控高度变化的js代码
- 扩展jQuery 键盘事件的几个基本方法
- jQuery 扩展对input的一些操作方法
- jquery 弹出层实现代码
- 网页禁用右键实现代码(JavaScript代码)
- JavaScript 工具库 Cloudgamer JavaScript Library v0.1 发布
- JScript 脚本实现文件下载 一般用于下载木马
- javascript 通过封装div方式弹出div窗体
- javascript 面向对象,实现namespace,class,继承,重载