当前位置:首页 » 编程语言 » 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
}
热点内容
phpmysql连接超时 发布:2025-07-03 17:05:09 浏览:795
服务器怎么设置电脑远程端口 发布:2025-07-03 16:28:46 浏览:72
电信无线路由器官方密码是什么 发布:2025-07-03 16:25:00 浏览:773
空间只能申请访问 发布:2025-07-03 16:23:27 浏览:735
华硕天选2air配置如何选择 发布:2025-07-03 16:10:09 浏览:571
asp搜索源码 发布:2025-07-03 15:49:55 浏览:235
医美大数据库 发布:2025-07-03 15:47:07 浏览:357
c语言将二进制转化为十进制 发布:2025-07-03 15:32:47 浏览:988
c语言帮助文档 发布:2025-07-03 15:22:43 浏览:320
双端口存储器在情况下会发生读写冲突 发布:2025-07-03 15:12:54 浏览:271