日期/时间转换为本地时间 [英] Date/Time conversion to local time
本文介绍了日期/时间转换为本地时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
请参阅下面的code
日期日期1 =新的日期(HttpDateParser.parse(dateString);
偏移为int = TimeZone.getTimeZone(GMT + 5:30)getRawOffset();
date1.setTime(date1.getTime()+偏移量);
字符串模式=YYYY-MM-DD HH:MMA
SimpleDateFormat的日期=新的SimpleDateFormat(模式);
字符串dateNow = date.format(DATE1);
它转换罚款在模拟器印度标准时间。
当我尝试在设备上使用,时间不变。
解决方案
解析日期字符串,并自1970年1月1日,00:00:00 GMT返回的毫秒数。
但是,如果我通过毫秒到date()函数发生什么。
它会自动给出日期转换为用户的本地时区。干杯。
下面code所做的一切都很好。
日期日期1 =新的日期(HttpDateParser.parse((字符串)kValue))
在DATE1已经转换为用户的本地时区。
See the below code
Date date1 = new Date(HttpDateParser.parse(dateString);
int offset = TimeZone.getTimeZone("GMT+5:30").getRawOffset();
date1.setTime(date1.getTime() + offset);
String pattern = "yyyy-MM-dd hh:mma";
SimpleDateFormat date = new SimpleDateFormat(pattern);
String dateNow = date.format(date1);
It converts fine to indian standard time in simulator. When i try to use in device, the time remain unchanged.
解决方案
Parses a date string and returns the number of milliseconds since January 1, 1970, 00:00:00 GMT.
But what happen if i pass milliseconds to Date() function. It automatically gives date converting to user's local timezone. Cheers.
The below code have done everything fine.
Date date1 = new Date(HttpDateParser.parse((String)kValue))
The date1 already converted to user's local timezone.
这篇关于日期/时间转换为本地时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文