js获取年月日时分秒星期

<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script language="javascript">
function getCurDate()
{
var d = new Date();
var week;
switch (d.getDay()){
case 1: week="星期一"; break;
case 2: week="星期二"; break;
case 3: week="星期三"; break;
case 4: week="星期四"; break;
case 5: week="星期五"; break;
case 6: week="星期六"; break;
default: week="星期天";
}

var years = ( d.getYear() < 1900 ) ? ( 1900 + d.getYear() ) : d.getYear();
var month = add_zero(d.getMonth()+1);
var days = add_zero(d.getDate());
var hours = add_zero(d.getHours());
var minutes = add_zero(d.getMinutes());
var seconds=add_zero(d.getSeconds());
var ndate = years+"年"+month+"月"+days+"日 "+hours+":"+minutes+":"+seconds+" "+week;
divT.innerHTML= ndate;
}
function add_zero(temp)
{
if(temp<10) return "0"+temp;
else return temp;
}
setInterval("getCurDate()",100);
</script>
</head>

<body>

<span id="divT"></span>
</body>
</html>

时间: 2024-10-06 00:48:09

js获取年月日时分秒星期的相关文章

获取年月日时分秒

NSDate *now = [NSDate date]; NSCalendar *cal = [NSCalendar currentCalendar]; unsigned int unitFlags = NSWeekdayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit; NSDateComponents *dd = [cal components:unitFlags fromDate:

java Date获取 年月日时分秒

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 package com.util; import java.text.DateFormat; import java.util.Calendar; import java.util.Date; public class Test {     public vo

年月日 时分秒 星期 农历 实时刷新 时间插件

效果如图(注释掉了农历),需要的话,请自行调出 话不多少,直接上代码 js代码部分 $(function(){ setInterval("currentTime()","1000"); }); function currentTime(){ var date = getCurrentDateTime(); var calendar = showCal(); $("#search-time").text(date); } /*获取当前日期*/ fu

js 获取当前年月日时分秒星期

$("#aa").click(function () { var date = new Date(); this.year = date.getFullYear(); this.month = date.getMonth() + 1; this.date = date.getDate(); this.day = new Array("星期日", "星期一", "星期二", "星期三", "星期四&

原生JS代码封装(获取年月日时分秒 )

function numberDoubled(n){ n = n+""; return n.length==1?"0"+n:n; } function date2string(d, sp){ sp = sp || "-"; var year = d.getFullYear(); var month = d.getMonth()+1; var date = d.getDate(); var hour = d.getHours(); var min

sqlserver 获取年月日 时分秒

select GETDATE() as '当前日期',DateName(year,GetDate()) as '年',DateName(month,GetDate()) as '月',DateName(day,GetDate()) as '日',DateName(dw,GetDate()) as '星期',DateName(week,GetDate()) as '周数',DateName(hour,GetDate()) as '时',DateName(minute,GetDate()) as '

Android Calendar获取年月日时分秒毫秒

开始使用new Date()测试,并用通过date.getMonth(),和date.getDay()获取,不过后来发现这两个访求是jdk1.1版本的,现在已经不用了,而且结果也不正确. int month = (date.get(Calendar.MONTH))+1; int day = date.get(Calendar.DAY_OF_MONTH); 获取当前的月份和日期 试了一下,果然正确 后来查看java doc文档,MONTH字段解释如下 Field number for get an

【第六篇】javascript显示当前的时间(年月日 时分秒 星期)

不多说自己上代码 这是我开始学javascript写的,现在发出来 <span id="clock" ></span> function time() { var today = new Date(); var hou; var time; var day; if (today.getHours() < 12 && today.getHours() >= 0) { hou = today.getHours(); time = &quo

获取年月日 时分秒

Calendar calendar = Calendar.getInstance(); int year = calendar.get(Calendar.YEAR); // 年 System.out.println(year); int month = calendar.get(Calendar.MONTH) + 1; // 月 System.out.println(month); int day = calendar.get(Calendar.DATE); // 日 System.out.pr