c# 如何在GMT时间和本地时间之间转换
发布网友
发布时间:2022-05-23 10:39
我来回答
共1个回答
热心网友
时间:2023-10-20 14:47
这个获取GMT时间的方法
public static Date getGMT8Time(){
Date gmt8 = null;
try {
Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT+8"),Locale.CHINESE); Calendar day = Calendar.getInstance();
day.set(Calendar.YEAR, cal.get(Calendar.YEAR));
day.set(Calendar.MONTH, cal.get(Calendar.MONTH));
day.set(Calendar.DATE, cal.get(Calendar.DATE));
day.set(Calendar.HOUR_OF_DAY, cal.get(Calendar.HOUR_OF_DAY));
day.set(Calendar.MINUTE, cal.get(Calendar.MINUTE));
day.set(Calendar.SECOND, cal.get(Calendar.SECOND));
gmt8 = day.getTime();
} catch (Exception e) {
System.out.println("获取GMT8时间 getGMT8Time() error !");
e.printStackTrace();
gmt8 = null;
}
return gmt8;
}
这个系统时间获取 用datetime.Now;知道了获取就容易转换了!