導航:首頁 > 編程語言 > 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相關的資料

熱點內容
wps的安裝程序在哪 瀏覽:317
用電腦怎麼更新ios系統文件在哪裡 瀏覽:724
查看電腦開啟wifi密碼 瀏覽:610
k28下載數據失敗是什麼意思 瀏覽:374
你使用過什麼網站 瀏覽:480
電腦存數據是什麼 瀏覽:205
linux下文件夾 瀏覽:426
微信使用什麼資料庫 瀏覽:762
數據恢復的軟體有哪些新聞 瀏覽:607
美術app課件怎麼做 瀏覽:86
htmlselect下拉框js 瀏覽:509
視頻文件如何放進ppt里 瀏覽:56
用什麼APP查二手事故車 瀏覽:174
pptx微信滑動 瀏覽:97
如何變更電子地圖數據 瀏覽:152
qq音樂app怎麼同步歌單 瀏覽:735
如何讓別人的qq凍結 瀏覽:997
如何手機視頻轉化為文件 瀏覽:550
如何畫文件 瀏覽:614
什麼叫數據備份 瀏覽:520

友情鏈接