java 获取服务器的时间,年月日时分秒

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java 获取服务器的时间,年月日时分秒相关的知识,希望对你有一定的参考价值。

然后把获取的时间返回到jsp页面显示出来,并且是动态的时间走动。 切记是动态的系统时间。
动态获取服务器的时间。

参考技术A 您这还挺神奇的。如果用java后台获取到时间,然后传到jsp页面。
还得动态不停的走,这传输的多频繁啊?我确实没见过

建议你找找javascript的代码。有很多的。
给出一种
function getCustomTime()

var nowtime=new Date();
var hours=nowtime.getHours();
hours=hours>9?hours:"0"+hours;
var minutes=nowtime.getMinutes();
minutes=minutes>9?minutes:"0"+minutes;

var disptime=hours+":"+minutes;
document.getElementById("hourminutes").innerhtml=disptime;
setTimeout("getCustomTime()",1000);

function getCustomMonth()

time=new Date();
year=time.getYear();
month=time.getMonth()+1;
month=month>9?month:"0"+month;
day=time.getDate();
day=day>9?day:"0"+day;
var disptime=year+"/"+month+"/"+day+'星期'+'日一二三四五六'.charAt(time.getDay());
document.getElementById("xq").innerHTML=disptime;
setTimeout("getCustomMonth()",1000);


然后再你需要的地方引用这两个函数就可以了本回答被提问者采纳
参考技术B function xunshi_date()
var date = new Date($.ajax(async: false).getResponseHeader("Date"));
// 获取本机
// var date = new Date();
this.year = date.getFullYear();
// 月、日、时、分、秒补零
this.month = date.getMonth() + 1;
this.date = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
this.hour = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
this.minute = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
this.second = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
var currentTime = this.year + "-" + this.month + "-" + this.date + ' ' + this.hour + ":" + this.minute + ":" + this.second;
$("#xunshi_date").val(currentTime);
参考技术C import java.text.SimpleDateFormat;
import java.util.Date;

<%
Date date = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
%>

<%=sdf.format(date.getTime());%>

自己每秒刷新 一次

js获取当前当前年月日时分秒,以及获取年月日(无时分秒),详情见补充!

参考技术A

1、新建一个HTML文件,命名为test.html。

2、在JS中使用new Date()获得当前系统的时间,并将其保存在变量d中。当前时间的年份使用getYear()方法从变量d中获得。

3、使用new Date()获得当前系统的时间,并将其保存在变量d中。当前时间的月份使用getMonth()方法从变量d中获得。

4、在JS中使用new Date()获得当前系统的时间,并将其保存在变量d中。当前时间的日期使用getDate()方法从变量d中获得。

5、在JS中使用new Date()获得当前系统的时间,并将其保存在变量d中。当前时间的小时使用getHours()方法从变量d中获得。

6、在JS中使用new Date()获得当前系统的时间,并将其保存在变量d中。当前时间的秒数使用getSeconds()方法从变量d中获得。

7、就完成了。

以上是关于java 获取服务器的时间,年月日时分秒的主要内容,如果未能解决你的问题,请参考以下文章

java获取的日期只显示年月日不显示时分秒,怎么处理

将日期转换成标准年月日时分秒形式插入数据库

13位时间戳转年月日时分秒

js 怎么获取年月日时分秒中的时分秒

JS 计算两个时间戳相差年月日时分秒

java 给固定日期(字符串)加上时分秒