欢迎访问 生活随笔!

凯发k8官方网

当前位置: 凯发k8官方网 > 编程语言 > php >内容正文

php

php计算时间差js,javascript如何计算时间差(引入外部字体文件)? -凯发k8官方网

发布时间:2024/10/14 php 30 豆豆
凯发k8官方网 收集整理的这篇文章主要介绍了 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

本章给大家带来用javascript如何计算时间差(引入外部字体文件)?有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。

javascript date() 对象:

new date() :时间对象,会把当前时间作为其初始值;

setfullyear() :用于设置月份,可有三个参数,setfullyear(year,month,day);

sethours() :设置指定时间的小时,可有四个参数,sethours(hour,min,sec,millisec);

getdate() :返回月份的某一天;

getmonth() :返回表示月份的数字;

getfullyear() :返回一个表示年份的 4 位数字;

gettime() :返回距 1970 年 1 月 1 日之间的毫秒数;

setfullyear() :设置年份;

setdate() :设置日;

代码实例:

css代码:@font-face{

font-family: "digital-7 mono";

src: ;

}

div{

width: 500px;

}

.contain{

text-align: right;

font-size: 18px;

margin-top: 10px;

margin-bottom: 10px;

}

.contain span{

font-family: "digital-7 mono";

font-size: 36px;

color: #555;

padding-left: 10px;

}

html代码:

js代码:

var displaymode = 1;

var time;

$(".contain").click(function(){

displaymode *= -1;

time(time, displaymode);

});

// 返回不同月份不同天数的方法

function getdaysinmonth(month) {

var data = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];

return data[month];

}

// 设置开始时间

function start(year,month,day,hour,min,sec,mill){

var starttime =new date();

starttime.setfullyear(year,month-1,day);

starttime.sethours(hour,min,sec,mill);

time =starttime;

return time;

}

start(2015,2,20,21,0,0,0);

function time(date,mode){

var years = nan;

var months = nan;

var current =new date();

var seconds =(date.parse(current) - date.parse(date)) /1000; //获取时间差的秒数

var days =math.floor(seconds / (3600 * 24)); //总天数

seconds = seconds % (3600 * 24); //总秒数 % 一天的秒数 下面的同理

var hours =math.floor(seconds / 3600);

seconds = seconds % 3600;

var minutes = math.floor(seconds / 60);

seconds = seconds % 60;

// 判断假如时分秒小时10的话 前面加0

(seconds <10)? seconds ="0" seconds:seconds=seconds;

(hours <10)? hours ="0" hours:hours=hours;

(minutes <10)? minutes ="0" minutes:minutes=minutes;

if (mode == 1) {

days = current.getdate() - date.getdate(); //当前日 - 开始日

if (days < 0) {

days = getdaysinmonth(current.getmonth());

current.setdate(current.getdate() -1);

}

months = current.getmonth() - date.getmonth();

if (months < 0) {

months = 12;

current.setfullyear(current.getfullyear() - 1);

}

years = current.getfullyear() - date.getfullyear();

} else {

days = math.floor((current.gettime() - date.gettime()) / (1000 * 3600 * 24));

}

var result = (years > 0 ? "" years " year ":"")

result = (months >= 0 ? "" months " month ":"");

result = "" days " day ";

result = "" hours " hr "

result = "" minutes " min "

result = "" seconds " sec"

$(".contain").html(result);

}

time(time,displaymode);

setinterval(function(){

time(time,displaymode);

},1000)

不用安装到本地,直接引用外部字体文件@font-face{

font-family: "digital-7 mono";

src: ;

}

url 是文件的路径

总结

以上是凯发k8官方网为你收集整理的的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得凯发k8官方网网站内容还不错,欢迎将凯发k8官方网推荐给好友。

  • 上一篇:
  • 下一篇:
网站地图