導航:首頁 > 編程語言 > javaapr

javaapr

發布時間:2024-11-15 08:32:09

java里如何轉換"Wed Apr 11 16:18:42 +0800 2012"這樣的日期格式,我希望把它轉成long型的毫秒數

package Serial2;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

public class DateTest {

public static final String SOURCE = "Wed Apr 11 16:18:42 +0800 2012";

public static void main(String[] args) throws ParseException{

SimpleDateFormat sdf = new SimpleDateFormat(
"EEE MMM dd HH:mm:ss Z yyyy", new Locale("ENGLISH", "CHINA"));

Date myDate = sdf.parse(SOURCE);
System.out.println(myDate);

sdf.applyPattern("EEE MMM dd HH:mm:ss Z yyyy");
System.out.println(sdf.format(myDate));

SimpleDateFormat sdf2 = new SimpleDateFormat(
"yyyy-MM-dd HH:mm:ss", new Locale("CHINESE", "CHINA"));
System.out.println(sdf2.format(myDate));

sdf2.applyPattern("yyyy年MM月dd日 HH時mm分ss秒");
System.out.println(sdf2.format(myDate));

long miliSeconds = myDate.getTime();
System.out.println("自 1970 年 1 月 1 日 00:00:00 GMT 以來此 Date 對象經過的毫秒數為:"+miliSeconds+"毫秒");

/*
Wed Apr 11 16:18:42 CST 2012
Wed Apr 11 16:18:42 +0800 2012
2012-04-11 16:18:42
2012年04月11日 16時18分42秒
自 1970 年 1 月 1 日 00:00:00 GMT 以來此 Date 對象經過的毫秒數為:1334132322000毫秒
*/
}
}

閱讀全文

與javaapr相關的資料

熱點內容
maya粒子表達式教程 瀏覽:84
抖音小視頻如何掛app 瀏覽:283
cad怎麼設置替補文件 瀏覽:790
win10啟動文件是空的 瀏覽:397
jk網站有哪些 瀏覽:134
學編程和3d哪個更好 瀏覽:932
win10移動硬碟文件無法打開 瀏覽:385
文件名是亂碼還刪不掉 瀏覽:643
蘋果鍵盤怎麼打開任務管理器 瀏覽:437
手機桌面文件名字大全 瀏覽:334
tplink默認無線密碼是多少 瀏覽:33
ipaddgm文件 瀏覽:99
lua語言編程用哪個平台 瀏覽:272
政采雲如何導出pdf投標文件 瀏覽:529
php獲取postjson數據 瀏覽:551
javatimetask 瀏覽:16
編程的話要什麼證件 瀏覽:94
錢脈通微信多開 瀏覽:878
中學生學編程哪個培訓機構好 瀏覽:852
榮耀路由TV設置文件共享錯誤 瀏覽:525

友情鏈接