当前位置:首页 » 编程语言 » java本地时间

java本地时间

发布时间: 2023-07-04 11:46:08

A. java utc时间转本地时间

JAVA中将UTC时间转换为本地时间的方法,其他的时区转换与此类似。
public static String utc2Local(String utcTime, String utcTimePatten,
String localTimePatten) {
SimpleDateFormat utcFormater = new SimpleDateFormat(utcTimePatten);
utcFormater.setTimeZone(TimeZone.getTimeZone("UTC"));//时区定义并进行时间获取
Date gpsUTCDate = null;
try {
gpsUTCDate = utcFormater.parse(utcTime);
} catch (ParseException e) {
e.printStackTrace();
}
SimpleDateFormat localFormater = new SimpleDateFormat(localTimePatten);
localFormater.setTimeZone(TimeZone.getDefault());
String localTime = localFormater.format(gpsUTCDate.getTime());
return localTime;
}

B. java中utc时间怎么转换为本地时间

计算机用的是unix纪元,1970年1月1日 0时0分 UTC(协调世界时 即升级版的格林威治时间)
可以说是英国标准时间。

中国是UTC+8 八区,中国本地时间要在以上标准时间上面加8小时。

反映在java的timemilli毫秒时是,
long china_ts=System.currentTimeMillier()+1000*60*60*8;
但只在不支持Java SE时区的早期版本(比如Java Card,Java ME/MIDP1.0)才需要自己手工加。
现在的java系统本身有时区库,用Calendar/Date类,会自动调整时区。不需要再手动算。按以上加法会画蛇添足。

C. Java 如何显示当前系统日期与时间

通过new Date获取当前的日期与时间

示例:

publicstaticvoidmain(String[]args){
Datenow=newDate();//获取当前时间
SimpleDateFormatdateFormat=newSimpleDateFormat("yyyy/MM/ddHH:mm:ss");//格式化当前日期时间,显示如2015/06/2714:22:22
}
热点内容
数据库查询命令是什么 发布:2025-05-07 00:41:58 浏览:436
一汽大众途岳哪个配置最好 发布:2025-05-07 00:36:23 浏览:578
cFTP在服务器创建文件夹 发布:2025-05-07 00:25:57 浏览:544
网站数据库的软件 发布:2025-05-07 00:25:51 浏览:233
python怎么终止程序 发布:2025-05-07 00:25:50 浏览:782
引流脚本快手 发布:2025-05-07 00:20:53 浏览:965
android缩放bitmap 发布:2025-05-06 23:59:27 浏览:81
方舟电脑进服务器正确方法 发布:2025-05-06 23:41:51 浏览:217
网络的密码多少位 发布:2025-05-06 23:36:51 浏览:142
密码锁停电后怎么解决 发布:2025-05-06 23:35:52 浏览:591