代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
Js
】
计算宝宝出生后的年龄
作者:
/ 发布于
2017/2/3
/
712
//获取出生天数、时、分、秒 function getGrowTime(birthday) { var currentTime = Date.parse(new Date()); var myTime = new Date(birthday); var myTimeStamp = Date.parse(myTime); var gapSec = (currentTime - myTimeStamp)/1000; var day = 0; var hour = 0; var min = 0; var sec = 0; if(gapSec/(60*60*24) > 0) { day = (gapSec-gapSec%(60*60*24))/(60*60*24); gapSec = gapSec%(60*60*24); if((gapSec/3600) > 0) { hour = (gapSec-gapSec%3600)/3600; gapSec = gapSec%3600; if((gapSec/60) > 0) { min = (gapSec-gapSec%60)/60; sec = gapSec%60; } else { sec = gapSec; } } else { if((gapSec/60) > 0) { min = (gapSec-gapSec%60)/60; sec = gapSec%60; } else { sec = gapSec; } } } else { if((gapSec/3600) > 0) { hour = (gapSec-gapSec%3600)/3600; gapSec = gapSec%3600; if((gapSec/60) > 0) { min = (gapSec-gapSec%60)/60; sec = gapSec%60; } else { sec = gapSec; } } else { if((gapSec/60) > 0) { min = (gapSec-gapSec%60)/60; sec = gapSec%60; } else { sec = gapSec; } } } var dateStr = (day<10? ("0"+day): day)+"天 " + (hour<10? ("0"+hour): hour)+"时 " + (min<10? ("0"+min): min)+"分 " + (sec<10? ("0"+sec): sec)+"秒"; return dateStr; } 计算宝宝从出生到现在的周岁、月、天、时、分、秒 //获取出生年龄,周岁、月、天、时、分、秒 function getGrowAge(birthday) { var now = new Date(); var year = now.getFullYear(); var month = now.getMonth() + 1; var day = now.getDate(); var hour = now.getHours(); var minute = now.getMinutes(); var second = now.getSeconds(); var myDate = new Date(birthday); var myYear = myDate.getFullYear(); var myMonth = myDate.getMonth() + 1; var myDay = myDate.getDate(); var myHour = myDate.getHours(); var myMinute = myDate.getMinutes(); var mySecond = myDate.getSeconds(); var gapSecond = second - mySecond; if(gapSecond < 0) { minute -= 1; gapSecond = 60 - mySecond + second; } var gapMinute = minute - myMinute; if(gapMinute < 0) { hour -= 1; gapMinute = 60 - myMinute + minute; } var gapHour = hour - myHour; if(gapHour < 0) { day -= 1; gapHour = 24 - myHour + hour; } var gapDay = day - myDay; if(gapDay < 0) { month -= 1; gapDay = getDaysOfMonth(birthday) - myDay + day; } var gapMonth = month - myMonth; if(gapMonth < 0) { year -= 1; gapMonth = 12 - myMonth + month; } var gapYear = year - myYear; if(gapYear < 0) { gapYear = 0; } var dateStr = gapYear+"岁 " + (gapMonth<10? ("0"+gapMonth): gapMonth)+"月 " + (gapDay<10? ("0"+gapDay): gapDay)+"天 " + (gapHour<10? ("0"+gapHour): gapHour)+"时 " + (gapMinute<10? ("0"+gapMinute): gapMinute)+"分 " + (gapSecond<10? ("0"+gapSecond): gapSecond)+"秒"; return dateStr; } 还有两个计算所须的方法: //获取当月的天数 function getDaysOfMonth(dateStr) { var date = new Date(dateStr); var year = date.getFullYear(); var mouth = date.getMonth() + 1; var day = 0; if(mouth == 2) { day= isLeapYear(year) ? 29 : 28; } else if(mouth == 1 || mouth == 3 || mouth == 5 || mouth == 7 || mouth == 8 || mouth == 10 || mouth == 12) { day= 31; } else { day= 30; } return day; } //判断是否为闰年 function isLeapYear(year) { return (year%4==0 && year%100!=0)||(year%400==0); }
试试其它关键字
同语言下
.
Jquery搜索框获取回车事件
.
H5页面添加倒计时,然后自动跳转
.
通过user-agent判断h5页面是在哪个手机App(QQ、微信
.
nginx 禁止未绑定的域名访问
.
JavaScript 获取按键,并屏蔽系统 Window 事件
.
H5之只允许微信浏览器打开,禁止从外部浏览器访问
.
微信打开网址添加在浏览器中打开提示的办法
.
实现JS复制、粘贴,Chrome/Firefox下可用
.
video视频播放,play()、pause()、duration时长、onen
.
HTML5实现MP3上传前的预览和播放时长的获取
可能有用的
.
Jquery搜索框获取回车事件
.
H5页面添加倒计时,然后自动跳转
.
通过user-agent判断h5页面是在哪个手机App(QQ、微信
.
nginx 禁止未绑定的域名访问
.
JavaScript 获取按键,并屏蔽系统 Window 事件
.
H5之只允许微信浏览器打开,禁止从外部浏览器访问
.
微信打开网址添加在浏览器中打开提示的办法
.
实现JS复制、粘贴,Chrome/Firefox下可用
.
video视频播放,play()、pause()、duration时长、onen
.
HTML5实现MP3上传前的预览和播放时长的获取
贡献的其它代码
Label
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3