导航:首页 > 编程语言 > java本地时间utc

java本地时间utc

发布时间:2022-05-28 15:13:26

1. 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;
}

2. JAVA UTC时间格式转换

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss);

sdf.format(new Data());

3. JAVA获取UTC时间出现某段时间算不出来

测试了一下,代码没问题,9点之前和10点之后也没有问题啊。

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

java utc转本地时间的方法:
1、创建一个格式化时间对象simpleDateFormat,并初始化格式yyyy-MM-dd HH:mm:ss:
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
2、创建时区对象utcZone,获取utc所在的时区
TimeZone utcZone = TimeZone.getTimeZone("UTC");
3、设置utc时区,为转换做准备
simpleDateFormat.setTimeZone(utcZone);
4、获取本地时间,并转换
Date myDate = simpleDateFormat.parse(rawQuestion.getString("AskDateTime"));
5,按照上面的流程就转换本地时间了。

5. 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类,会自动调整时区。不需要再手动算。按以上加法会画蛇添足。

6. 关于菜鸟求教,java中获取当前时间转换成UTC毫秒值的搜索推荐

Date date = new Date();
long time = date.getTime();

7. Java 获取当前UTC时间+10秒并转换格式,求大神

importjava.text.SimpleDateFormat;
importjava.util.Calendar;

publicclassDateDemo{
publicstaticvoidmain(String[]args){
System.out.println(getDateString());
}

(){
Calendarcalendar=Calendar.getInstance();
calendar.add(Calendar.SECOND,10);
SimpleDateFormatsdf=newSimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
returnsdf.format(calendar.getTime());
}
}

中间是个T吗,其实我觉得空格会更好看。

8. java中utc时间怎么转换为本地时间格式

d.toLocaleString()不建议使用

9. 在java里面,如何得到UTC时间, 时间格式为:Tue Oct 12 00:00:00 UTC 0800 2010

Calendar gc = GregorianCalendar.getInstance();
cal.add(java.util.Calendar.MILLISECOND, -(zoneOffset + dstOffset));
//之后调用cal.get(int x)或cal.getTimeInMillis()方法所取得的时间即是UTC标准时间。
System.out.println("UTC:"+new Date(cal.getTimeInMillis()));

赠送其它时间方法,总有一款适合您
public static void main(String[] args) {
SimpleDateFormat foo = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
System.out.println("foo:"+foo.format(new Date()));

Calendar gc = GregorianCalendar.getInstance();
System.out.println("gc.getTime():"+gc.getTime());
System.out.println("gc.getTimeInMillis():"+new Date(gc.getTimeInMillis()));

//当前系统默认时区的时间:
Calendar calendar=new GregorianCalendar();
System.out.print("时区:"+calendar.getTimeZone().getID()+" ");
System.out.println("时间:"+calendar.get(Calendar.HOUR_OF_DAY)+":"+calendar.get(Calendar.MINUTE));
//美国洛杉矶时区
TimeZone tz=TimeZone.getTimeZone("America/Los_Angeles");
//时区转换
calendar.setTimeZone(tz);
System.out.print("时区:"+calendar.getTimeZone().getID()+" ");
System.out.println("时间:"+calendar.get(Calendar.HOUR_OF_DAY)+":"+calendar.get(Calendar.MINUTE));
Date time=new Date();

//1、取得本地时间:
java.util.Calendar cal = java.util.Calendar.getInstance();

//2、取得时间偏移量:
int zoneOffset = cal.get(java.util.Calendar.ZONE_OFFSET);

//3、取得夏令时差:
int dstOffset = cal.get(java.util.Calendar.DST_OFFSET);

//4、从本地时间里扣除这些差量,即可以取得UTC时间:
cal.add(java.util.Calendar.MILLISECOND, -(zoneOffset + dstOffset));

//之后调用cal.get(int x)或cal.getTimeInMillis()方法所取得的时间即是UTC标准时间。
System.out.println("UTC:"+new Date(cal.getTimeInMillis()));

Calendar calendar1 = Calendar.getInstance();
TimeZone tztz = TimeZone.getTimeZone("GMT");
calendar1.setTimeZone(tztz);
System.out.println(calendar.getTime());
System.out.println(calendar.getTimeInMillis());

}

运算结果是Tue Oct 19 16:54:57 CST 2010 符合你的要求
只是以毫秒来算的

10. JAVA时间换算问题UTC BJT

else{UTC=BJT;}改成else{UTC=BJT;}elseif(800<BJT<2359)改成elseif(800<BJT&&BJT<2359)if(0<BJT<800)改成if(0<BJT&&BJT<800)c语言中没有a<x<b这样的形式。要用&&或者||来进行连接

阅读全文

与java本地时间utc相关的资料

热点内容
s曲线加减速算法 浏览:399
可编程序控制器原理及应用答案 浏览:454
小熊编程教程 浏览:908
word转换成pdf转换器免费下载 浏览:608
群体智能基本算法 浏览:370
可编程软件分为哪两种 浏览:340
格林什么app可以看 浏览:697
飞卢app仙侠热卖推荐怎么样 浏览:722
飞秋上传文件到共享文件夹 浏览:691
服务器的共享文件夹如何访问 浏览:232
复盛螺杆压缩机讲解 浏览:332
柱在基础插筋需要加密吗 浏览:80
51单片机中断寄存器 浏览:65
压缩文件后有病毒怎么办 浏览:618
苹果ipad怎么登安卓王者账号 浏览:862
街头足球服务器已满是什么意思 浏览:462
androidspeex回音消除 浏览:133
加密会议什么意思 浏览:34
ubuntu命令行联网 浏览:7
37选7中奖概率及算法 浏览:593