javascript中日期函数Date详解
对象: 日期
Date是javascript预定义主题. 该主题包括可获取或设置系统日期、时间、月、日、小时、分钟、秒等等。包括函数方法获取 UTC 格式的日期。 UTC 是国际标准时间,也称格林尼治标准时间(Greenwich Mean Time)。
在使用这些方法前可先声明一个主题。
创建新日期主题
示例代码:var exd = new Date();
调用"new Date()" 将创建一个日期主题。该主题可用于调用过程或函数。我们必须在变量中获取该主题。在上述示例代码中该主题存储于变量 exd 中。
以下将使用 exd 作为示例。
方法
示例代码
结果
说明
getDate()
exd = new Date();
exd.getDate();
23 9
getDate() 方法返回您当前系统日期中的天数。 其范围为 1 到 31。
getUTCDate()
exd = new Date();
exd.getUTCDate();
23 9
getUTCDate() 方法返回 UTC 日期中的天数。 UTC 是国际标准时间。
getMonth()
exd = new Date();
exd.getMonth();
3 3
getMonth() 方法返回您系统日期中的月份。 其范围是从 1 到 12. 1 是1月, 12 是12月。
getUTCMonth()
exd = new Date();
exd. getUTCMonth();
3 3
getUTCMonth() 方法返回您系统日期中的 UTC 时间中的月份。
getDay()
exd = new Date();
exd.getDay();
5 5
getDay() 方法返回您系统日期为一周中的星期几。 其返回范围为从 1 到 7. 1 为星期日, 2 是星期一, 到 7 为星期六。
getUTCDay()
exd = new Date();
exd.getUTCDay();
5 5
getUTCDay() 方法返回您系统 UTC 日期是一周中的星期几。
getHours()
exd = new Date();
exd.getHours();
14 20
getHours() 方法返回您系统日期的小时。 该范围是 0 到 24.
getUTCHours()
exd = new Date();
exd.getUTCHours();
6 12
getUTCHours() 方法返回您系统 UTC 日期的小时。 [中国时间比国际标准时间(UTC)快 8 小时].
getMinutes()
exd = new Date();
exd.getMinutes();
2 32
getMinutes() 方法返回您系统日期的分钟。 其结果范围是 0 到 59。
getUTCMinutes()
exd = new Date();
exd. getUTCMinutes();
2 32
getUTCMinutes() 方法返回您系统 UTC 日期的分钟。
getSeconds()
exd = new Date();
exd.getSeconds();
1 30
getSeconds() 方法返回您系统日期的分钟。 其结果范围是 0 到 59。
getUTCSeconds()
exd = new Date();
exd. getUTCSeconds();
1 30
getUTCSeconds() 方法返回您系统 UTC 日期的秒钟。
getMilliseconds()
exd
相关文档:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="gb2312">
<head>
<head>
<title> 关于arguments,callee,caller等的测试 &l ......
正在看 javascript高级程序设计 ,其中关于分组里面的一句代码不是太理解:
通过配合使用String对象的replace()方法及反向引用,就可以定义自己的trim()方法:
String.prototype.trim = function() {
var reExtraSpace = /^\s+(.*?)\s+$/;
return this.replace(reExtraSpace,"$1");
}
一开始怎么也不 ......
JavaScript读取Txt文件
<html>
<head>
<title>new page</title>
<script>
GetHeader(src) {
var ForReading=1;
var fso=new ActiveXObject("Scripting.FileSystemObject");
var f=fso.OpenTextFile(src,ForReading);
return(f.ReadAll());
}
var arr=GetHe ......
特殊JavaScript脚本:
1.禁用(恢复)href超级链接.
2.javascript中调用vbs对话框实现Confirm,可以显示Yes,No,还有各种图标,仅IE下有效.
3.限制上传文件类型为jpg.
4.限制离开当前页面,在离开时提示.仅限制窗口关闭或通过某个href超级链接离开.(页面刷新和地址栏改变时不提示)
demo.html如下:
<html>
&n ......
jQuery, MooTools, Prototype 等优秀的
JavaScript 框架拥有各种强大的功能,包括绘制 Web 图表,使用这些框架以及相应插件,我们可以非常轻松地实现曲线图,圆饼图,柱状图等
Web 图表的绘制,而不必象以往那样通过复杂的 Flash 技术实现。本文介绍了9个优秀的基于 JavaScript 与 CSS& ......