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

熱點內容
js驗證checkbox是否勾選 瀏覽:991
qq520紅包病毒是真的嗎 瀏覽:875
文件夾里的數字是什麼 瀏覽:118
us數據線怎麼連接車載音樂 瀏覽:320
撥號晶元程序寫入 瀏覽:847
掃描到電腦文件位置 瀏覽:941
微信里怎麼錄音文件 瀏覽:527
vba連接sql資料庫 瀏覽:943
iphone不用數據線怎麼連接電腦 瀏覽:865
分享文件文件名後有數字 瀏覽:940
6s4G網路怎麼設置 瀏覽:197
72版本神器知識新上限 瀏覽:92
logo程序下載 瀏覽:873
led屏幕編程是什麼意思 瀏覽:338
在linux如何修改文件內容 瀏覽:378
如何找出a列不等於b列的數據 瀏覽:472
金磚五國青年哪個app好 瀏覽:442
word2007橫向縱向混排 瀏覽:13
有什麼免費看英語單詞的app嗎 瀏覽:386
蘋果5s一直搜索網路 瀏覽:51

友情鏈接