js日期

<script>javascript

Date()方法得到當日的日期java

<script type="text/javascript">ip

document.write(Date())ci

</script>字符串

getTime()計算從1970年到今天有多少年get

<script type="text/javascript">it

var minutes=1000*60方法

var hours=minutes*60im

var days=hours*24字符

var years=days*365

var d=new Date()

var t=d.getTime()

var y=t/years

document.write("it's been:"+y+"years since 1970/01/01!")

</script>

setFullYear()獲得精準的日期

<script type="text/javascript>

var d=new Date()

d.setFullYear(1992,10,3)

document.write(d)

</script>

toUTCString()將當日的日期(根據UTC轉換爲字符串

<script type="text/javascript">

var d=new Date()

document.write(d.toUTCString())

</script>

getDay()來顯示星期,而不單單是數字

<script type="text/javascipt">

var d=new Date()

var weekday=new Array(7)

weekday[0]="星期日"

weekday[0]="星期一"

weekday[0]="星期二"

weekday[0]="星期三"

weekday[0]="星期四"

weekday[0]="星期五"

weekday[0]="星期六"

document.write("今天是"+weekday[d.getDay()])

</scripe>

相關文章
相關標籤/搜索