Java時間操作(一):關於UTC格式時間處理


Java中獲取形如:20160811T122132+08 格式,可以通過如下方法

package com.mc.others;

public class UTCTimeTest {
@Test
public void test1() {
Calendar calendar = Calendar.getInstance();
DateFormat dtf = new SimpleDateFormat("yyyyMMdd'T'HHmmssZ");
Date now = calendar.getTime();
String format = dtf.format(now);
System.out.println(format);//20160803T222649+0800
}
@Test
public void test2() {
Date now = new Date();
DateFormat dtf = new SimpleDateFormat("yyyyMMdd'T'HHmmssZZ");
String format = dtf.format(now);
System.out.println(format);//20160803T221641+0800
}
@Test
public void test3() {
// org.joda.time.DateTime;
DateTime dateTime = new DateTime();
String format = dateTime.toString();
System.out.println(format);//2016-08-03T22:14:19.293+08:00
}
@Test
public void test4() {
DateTime dateTime = new DateTime();
String format = dateTime.toString("yyyyMMdd'T'HHmmssZZ");//20160803T221822+08:00
System.out.println(format);
}
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM