Javascript_Date对象

// Date 对象
// 功能 处理日期和时间
// 创建方法:

// new Date() // 返回现在的时间 GMT
// new Date(毫秒);
// new Date(年,月,日,时,分,秒,毫秒)
// new Date("2018-8-8 12:00")

/*
英语单词
year 年
month 月
day 日
hours 时
minutes 分
seconds 秒
milliseconds 毫秒
*/

var time = new Date();
console.log( "今天是几号:",time.getDate());

console.log( "今天星期几:",time.getDay()); // 星期日 = 0,其余一样

console.log( "今年是:",time.getFullYear());

console.log( "现在是几点:",time.getHours()); // 0-23点

console.log( "现在的毫秒:",time.getMilliseconds()); // 0-999

console.log( "现在的月份:",time.getMonth()+ 1); // 从0开始

console.log( "现在的秒数:",time.getSeconds());

console.log( "获取1970-1-1---至今的毫秒数 ",time.getTime());

console.log( "获取GMT与本地的分钟差:",time.getTimezoneOffset());

console.log( "现在的时间是:",time.getHours(), ":",time.getMinutes(), ":",time.getSeconds())



// UTC(世界统一时间)
console.log( "UTC-日:",time.getUTCDate()); // 1-31

console.log( "UTC-星期",time.getUTCDay()); // 0-6 和getDay()相似

console.log( "UTC-年: ",time.getUTCFullYear());

console.log( "UTC-时: ",time.getUTCHours());

console.log( "UTC-毫秒",time.getUTCMilliseconds());

console.log( "UTC-分",time.getUTCMinutes());

console.log( "UTC-月",time.getUTCMonth()); //0-11

console.log( "UTC-秒",time.getUTCSeconds());

console.log( "UTC时间",time.getUTCHours(), ":",time.getUTCMinutes(), ":",time.getSeconds());



// 设置Date
var a = Date.parse( "March 11, 2018"); // 返回1970-1-1 到设置的毫秒数
var date = new Date();

// UTC也有这七个 date.setUTCMonth 以此类推
date.setMonth( 6);
date.setDate( 6);
date.setFullYear( 6666);
date.setMinutes( 56);
date.setHours( 16);
date.setSeconds( 16);
date.setTime( 66666666666666);

console.log(date);


// 转换日期

var date = new Date();

console.log(date.toDateString()); // 星期 月 日 年 英文缩写显示 除了年2018

console.log(date.toISOString()); // ISO标准格式

console.log(date.toJSON()); // JSON格式返回

console.log(date.toLocaleDateString()); // 2018/1/1
// 根据本地date格式,把对象转换为字符串显示
console.log(date.toLocaleTimeString()); // 下午14:00:00

console.log(date.toLocaleString()); // 将上面两个方法结合了


console.log(date.toTimeString());
// 将date对象转换为字符串
console.log(date.toDateString());

console.log(date.toString()); // 将上面两个方法结合了

console.log(date.toUTCString()); // UTC时间转换为字符串

console.log(date.valueOf()); // 值不变


// 动态加载时间
function good() {
var date = new Date();
document.body.innerHTML = date.getHours()+ ":"+date.getMinutes()+ ":"+date.getSeconds();
time = setTimeout( function(){
good();
}, 1000);
}
good();


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值