Android 怎么把GMT+8.0转化为UTC时间
当用户把信息上传到服务器上时,对于时间,常常用UTC时间。怎么将GMT+8.0时间转化为UTC时间呢?请参考下面的函数:
[java] public CharSequence GetUTCTime() {
Calendar cal = Calendar.getInstance(Locale.CHINA);
int zoneOffset = cal.get(java.util.Calendar.ZONE_OFFSET);
int dstOffset = cal.get(java.util.Calendar.DST_OFFSET);
cal.add(java.util.Calendar.MILLISECOND, -(zoneOffset + dstOffset));
return DateFormat.format("yyyy'-'MM'-'dd'T'kk':'mm':'ss'Z'", cal);
}
public CharSequence GetUTCTime() {
Calendar cal = Calendar.getInstance(Locale.CHINA);
int zoneOffset = cal.get(java.util.Calendar.ZONE_OFFSET);
int dstOffset = cal.get(java.util.Calendar.DST_OFFSET);
cal.add(java.util.Calendar.MILLISECOND, -(zoneOffset + dstOffset));
return DateFormat.format("yyyy'-'MM'-'dd'T'kk':'mm':'ss'Z'", cal);
}
主要用到的类:java.util.Calendar和android.text.format.DateFormat
补充:移动开发 , Android ,