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(); //获取日期与时间
如果用这些来获取还是获取不到的话,发一下源代码,说明你哪个地方写错了。
年 月 日 时 分 秒 星期 。 如果按楼主要求,星期换下就可以,也就是
var ndate = years+"年"+month+"月"+days+"日 "+hours+":"+minutes+":"+seconds+" "+week;
这句 ,换成
var ndate = years+"年"+month+"月"+days+"日 "+week+" "+hours+":"+minutes+":"+seconds;
<html>
<head>
<title></title>
<script language="javascript">
function getCurDate()
{
var d = new Date();
var week;
switch (dgetDay()){
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 = dgetYear();
var month = add_zero(dgetMonth()+1);
var days = add_zero(dgetDate());
var hours = add_zero(dgetHours());
var minutes = add_zero(dgetMinutes());
var seconds=add_zero(dgetSeconds());
var ndate = years+"年"+month+"月"+days+"日 "+hours+":"+minutes+":"+seconds+" "+week;
divTinnerHTML= ndate;
}
function add_zero(temp)
{
if(temp<10) return "0"+temp;
else return temp;
}
setInterval("getCurDate()",100);
</script>
</head>
<body>
<div id="divT"></div>
</body>
</html>
Timestamp time = new Timestamp(SystemcurrentTimeMillis());
Systemoutprintln(timetoString());
日期时间都有
Date d = new Date();
String date = dtoLocaleString(); //获取当前日期,然后你可以自己对这个字符串进行处理。或者用dgetDate();等方法,单独取它的日期等等。
javascript 自带有个对象(构造函数),Date()下面是代码:
var myDate = new Date(); //实例一个时间对象;
myDategetFullYear(); //获取系统的年;
myDategetMonth()+1; //获取系统月份,由于月份是从0开始计算,所以要加1
myDategetDate(); // 获取系统日,
myDategetHours(); //获取系统时,
myDategetMinutes(); //分
myDategetSeconds(); //秒
// JavaScript Document by Youzi, send email to youzi_friend@163com to connect author
///////////////////////////////////////////////// showDate Start
windowonload = function () {
showDate();
}
// Date Display Start
function showDate(){
var today = new Date();
var nowYear = todaygetFullYear();
var nowMonth = checkTime(todaygetMonth() + 1);
var nowDate = checkTime(todaygetDate());
var nowHour = checkTime(todaygetHours());
var nowMin = checkTime(todaygetMinutes());
var nowSec = checkTime(todaygetSeconds());
var weekday = new Array('星期日','星期一','星期二','星期三','星期四','星期五','星期六');
var nowDay = weekday[todaygetDay()];
/ 农历类调用 /
var date = new ChineseCalendar();
var chinaDate = datesolarDay2();
var dateDiv = documentgetElementById("showDate");
var dateTxt = nowYear +"年"+ nowMonth +"月"+ nowDate +"日 " + chinaDate +" "+ nowDay +" "+ nowHour +":"+ nowMin +":"+ nowSec;
if ((nowMonth == 02 && nowDate == 10) || chinaDate == "农历正月初一") {
dateTxt += "<br /> IT's BenBen's birthday today <br /> <strong>Happay birthday to BenBen</strong>!";
}
dateDivinnerHTML = dateTxt;
setTimeout('showDate()',500);
}
function checkTime(i){
if (i < 10) { i = "0" + i; }
return i;
}
//农历类
function ChineseCalendar(dateObj){
thisdateObj = (dateObj != undefined) dateObj : new Date();
thisSY = thisdateObjgetFullYear();
thisSM = thisdateObjgetMonth();
thisSD = thisdateObjgetDate();
thislunarInfo = [0x04bd8,0x04ae0,0570,0x054d5,0x0d260,0x0d950,0x16554,0x056a0,0x09ad0,0x055d2,
0x04ae0,05b6,04d0,0x0d250,0x1d255,0x0b540,0x0d6a0,0da2,0x095b0,0x14977,
0x04970,04b0,0x0b4b5,0x06a50,0x06d40,0x1ab54,0x02b60,0x09570,0x052f2,0x04970,
0x06566,0x0d4a0,0x0ea50,0x06e95,0x05ad0,0x02b60,0x186e3,0x092e0,0x1c8d7,0x0c950,
0x0d4a0,0x1d8a6,0x0b550,0x056a0,0x1a5b4,0x025d0,0x092d0,0x0d2b2,0950,0x0b557,
0x06ca0,0x0b550,0x15355,0x04da0,05b0,0x14573,0x052b0,09a8,0x0e950,0x06aa0,
0ea6,0b50,0x04b60,0ae4,0570,0x05260,0x0f263,0x0d950,0x05b57,0x056a0,
0x096d0,0x04dd5,0x04ad0,04d0,0x0d4d4,0x0d250,0x0d558,0x0b540,0x0b6a0,0x195a6,
0x095b0,0x049b0,0974,04b0,0x0b27a,0x06a50,0x06d40,0f46,0b60,0x09570,
0x04af5,0x04970,0x064b0,0x074a3,0x0ea50,0x06b58,0x055c0,0b60,0x096d5,0x092e0,
0x0c960,0x0d954,0x0d4a0,0x0da50,0x07552,0x056a0,0bb7,0x025d0,0x092d0,0x0cab5,
0950,0x0b4a0,0x0baa4,0d50,0x055d9,0x04ba0,05b0,0x15176,0x052b0,0930,
0x07954,0x06aa0,0d50,0x05b52,0x04b60,06e6,04e0,0x0d260,0x0ea65,0x0d530,
0x05aa0,0x076a3,0x096d0,0x04bd7,0x04ad0,04d0,0x1d0b6,0x0d250,0x0d520,0x0dd45,
0x0b5a0,0x056d0,0x055b2,0x049b0,0577,04b0,0a50,0x1b255,0x06d20,0da0,
0x14b63];
//传回农历 y年闰哪个月 1-12 , 没闰传回 0
thisleapMonth = function(y){
return thislunarInfo[y - 1900] & 0xf;
};
//传回农历 y年m月的总天数
thismonthDays = function(y, m){
return (thislunarInfo[y - 1900] & (0x10000 >> m)) 30 : 29;
};
//传回农历 y年闰月的天数
thisleapDays = function(y){
if (thisleapMonth(y)) {
return (thislunarInfo[y - 1900] & 0x10000) 30 : 29;
}
else {
return 0;
}
};
//传回农历 y年的总天数
thislYearDays = function(y){
var i, sum = 348;
for (i = 0x8000; i > 0x8; i >>= 1) {
sum += (thislunarInfo[y - 1900] & i) 1 : 0;
}
return sum + thisleapDays(y);
};
//算出农历, 传入日期对象, 传回农历日期对象
//该对象属性有 year month day isLeap yearCyl dayCyl monCyl
thisLunar = function(dateObj){
var i, leap = 0, temp = 0, lunarObj = {};
var baseDate = new Date(1900, 0, 31);
var offset = (dateObj - baseDate) / 86400000;
lunarObjdayCyl = offset + 40;
lunarObjmonCyl = 14;
for (i = 1900; i < 2050 && offset > 0; i++) {
temp = thislYearDays(i);
offset -= temp;
lunarObjmonCyl += 12;
}
if (offset < 0) {
offset += temp;
i--;
lunarObjmonCyl -= 12;
}
lunarObjyear = i;
lunarObjyearCyl = i - 1864;
leap = thisleapMonth(i);
lunarObjisLeap = false;
for (i = 1; i < 13 && offset > 0; i++) {
if (leap > 0 && i == (leap + 1) && lunarObjisLeap == false) {
--i;
lunarObjisLeap = true;
temp = thisleapDays(lunarObjyear);
}
else {
temp = thismonthDays(lunarObjyear, i)
}
if (lunarObjisLeap == true && i == (leap + 1)) {
lunarObjisLeap = false;
}
offset -= temp;
if (lunarObjisLeap == false) {
lunarObjmonCyl++;
}
}
if (offset == 0 && leap > 0 && i == leap + 1) {
if (lunarObjisLeap) {
lunarObjisLeap = false;
}
else {
lunarObjisLeap = true;
--i;
--lunarObjmonCyl;
}
}
if (offset < 0) {
offset += temp;
--i;
--lunarObjmonCyl
}
lunarObjmonth = i;
lunarObjday = offset + 1;
return lunarObj;
};
//中文日期
thiscDay = function(m, d){
var nStr1 = ['日', '一', '二', '三', '四', '五', '六', '七', '八', '九', '十'];
var nStr2 = ['初', '十', '廿', '卅', ' '];
var s;
if (m > 10) {
s = '十' + nStr1[m - 10];
}
else {
s = nStr1[m];
}
s += '月';
switch (d) {
case 10:
s += '初十';
break;
case 20:
s += '二十';
break;
case 30:
s += '三十';
break;
default:
s += nStr2[Mathfloor(d / 10)];
s += nStr1[d % 10];
}
return s;
};
thissolarDay2 = function(){
var sDObj = new Date(thisSY, thisSM, thisSD);
var lDObj = thisLunar(sDObj);
var tt = '农历' + thiscDay(lDObjmonth, lDObjday);
lDObj = null;
return tt;
};
thisweekday = function(){
var day = ["周日", "周一", "周二", "周三", "周四", "周五", "周六"];
return day[thisdateObjgetDay()];
};
thisYYMMDD = function(){
var dateArr = [thisSY, '年', thisSM + 1, '月', thisSD, '日'];
return dateArrjoin('');
}
}
网上找的,年月日,时分秒,星期,农历都有,你参考一下
/ 农历类用法: 源地址: >
打开前端编辑软件,新建一个html文件。
在html代码页面上创建一个点击按钮,给这个按钮添加一个获取当前时间的getTime方法,点击该按钮就会触发getTime方法。如图
<input type="button" value="当前时间" onclick="getTime()">
找到<title>标签,在这个标签后面新建一个<scrtip>标签。如图:
代码:<script type="text/javascript"></script>
在<script>标签里创建获取时间的getTime函数,然后使用new Date获取当前的时间。如图:
代码:function getTime(){ var date = new Date(); //创建时间对象}
在getTime函数中使用getFullYear()获取当前的年份;使用getMonth()获取当前的月份;使用getDay()获取当前日期。如图
代码:
var year = dategetFullYear(); //获取年 var month = dategetMonth();//获取月 var day = dategetDay(); //获取当日
组合时间,把获取到的年、月、日重新组合,然后使用alertd出当前日期。如图
代码:
var time = year+"-"+month+"-"+day; //组合时间alert("当前日期:"+time);
保存html代码后使用浏览器打开,点击获取时间按钮就会看到d出的当前时间。如图
所有代码:
<!DOCTYPE html><html><head> <meta charset="UTF-8"> <title>获取当前时间</title> <script type="text/javascript"> function getTime(){ var date = new Date(); //创建时间对象 var year = dategetFullYear(); //获取年 var month = dategetMonth();//获取月 var day = dategetDay(); //获取当日 var time = year+"-"+month+"-"+day; //组合时间 alert("当前日期:"+time); } </script></head><body> <input type="button" value="当前时间" onclick="getTime()"></body></html>
可以直接复制所有代码,粘贴到新建的html文件,保存后运行即可看到效果。
以上就是关于js书上看的 获取当前系统时间 为什么不对全部的内容,包括:js书上看的 获取当前系统时间 为什么不对、如何在js里获取系统时间,并在html中应用;、请问一下,如何用Java或者Javascript来获取系统已启动的时间等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)