
var myDate = new Date();
myDategetYear(); //获取当前年份(2位)
myDategetFullYear(); //获取完整的年份(4位,1970-)
myDategetMonth(); //获取当前月份(0-11,0代表1月)
myDategetDate(); //获取当前日(1-31)
myDategetDay(); //获取当前星期X(0-6,0代表星期天)
myDategetTime(); //获取当前时间(从197011开始的毫秒数)
myDategetHours(); //获取当前小时数(0-23)
myDategetMinutes(); //获取当前分钟数(0-59)
myDategetSeconds(); //获取当前秒数(0-59)
myDategetMilliseconds(); //获取当前毫秒数(0-999)
myDatetoLocaleDateString(); //获取当前日期
var mytime=myDatetoLocaleTimeString(); //获取当前时间
myDatetoLocaleString( ); //获取日期与时间
日期时间脚本库方法列表
DateprototypeisLeapYear 判断闰年
DateprototypeFormat 日期格式化
DateprototypeDateAdd 日期计算
DateprototypeDateDiff 比较日期差
DateprototypetoString 日期转字符串
DateprototypetoArray 日期分割为数组
DateprototypeDatePart 取日期的部分信息
DateprototypeMaxDayOfDate 取日期所在月的最大天数
DateprototypeWeekNumOfYear 判断日期所在年的第几周
StringToDate 字符串转日期型
IsValidDate 验证日期有效性
CheckDateTime 完整日期时间检查
daysBetween 日期天数差
js代码:
//---------------------------------------------------
// 判断闰年
//---------------------------------------------------
DateprototypeisLeapYear = function()
{
return (0==thisgetYear()%4&&((thisgetYear()%100!=0)||(thisgetYear()%400==0)));
}
//---------------------------------------------------
// 日期格式化
// 格式 YYYY/yyyy/YY/yy 表示年份
// MM/M 月份
// W/w 星期
// dd/DD/d/D 日期
// hh/HH/h/H 时间
// mm/m 分钟
// ss/SS/s/S 秒
//---------------------------------------------------
不一样。
不同的设备,本地的系统时间是不一样的,假如你电脑设定的时间是9:00那么js获取的就是9:00但是如果此时别人的电脑时间是10:00在别人的电脑上js获取的时间就是10:00。
s是客服端脚本,是不能直接获取服务器端的时间的,除非你用asp,或者jsp,php,等写一个动态的js脚本。
使用世界时来表达就行了,北京时间是第8时区,将世界时加上8小时就是北京时间。
var nowTime = new Date(new Date()getTime()+860601000);
北京时间显示为:
nowTimetoUTCString();
获取年月日全都使用世界时方法:
getUTCDate() 根据世界时从 Date 对象返回月中的一天 (1 ~ 31)
getUTCDay() 根据世界时从 Date 对象返回周中的一天 (0 ~ 6)
getUTCMonth() 根据世界时从 Date 对象返回月份 (0 ~ 11)
getUTCFullYear() 根据世界时从 Date 对象返回四位数的年份
getUTCHours() 根据世界时返回 Date 对象的小时 (0 ~ 23)
getUTCMinutes() 根据世界时返回 Date 对象的分钟 (0 ~ 59)
getUTCSeconds() 根据世界时返回 Date 对象的秒钟 (0 ~ 59)
getUTCMilliseconds() 根据世界时返回 Date 对象的毫秒(0 ~ 999)
以上就是关于js如何获取时间全部的内容,包括:js如何获取时间、js每个地区获取的时间戳是一样的吗、这串js javascript代码要如何修改才能让他在所有时区的电脑上都能统一显示北京时间呢我要用在ecshop上等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)