Java 获取当前UTC时间+10秒并转换格式,求大神
import java.text.SimpleDateFormat;
import java.util.Calendar;
public class DateDemo {
public static void main(String[] args) {
System.out.println(getDateString());
}
public static String getDateString() {
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.SECOND, 10);
SimpleDateFormat sdf = new SimpleDateFormat(“yyyy-MM-dd’T’HH:mm:ss”);
return sdf.format(calendar.getTime());
}
}
中间是个T吗,其实我觉得空格会更好看。
JAVA UTC时间格式转换
SimpleDateFormat sdf = new SimpleDateFormat(“yyyy-MM-dd HH:mm:ss);
sdf.format(new Data());
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;
}