本文目錄一覽:
- 1、JAVA 中獲取時間怎麼格式化?
- 2、java如何把英文的日期格式改成數字化的
- 3、java怎麼把時間轉換成”12thDecember2012,Wednesday12:12’這種形式
- 4、java將英文的日期格式轉中文
- 5、java如何實現各國時間格式轉換成yyyy-MM-dd HH:mm:ss時間格式?
- 6、在java中如何將數字的日期轉換成英文日期? 如 01/30轉換至January thirtieth.
JAVA 中獲取時間怎麼格式化?
時間格式化輸出主要有兩種方式,代碼如下:
//使用Calendar
Calendar now = Calendar.getInstance();
System.out.println(“年:” + now.get(Calendar.YEAR));
System.out.println(“月:” + (now.get(Calendar.MONTH) + 1));
System.out.println(“日:” + now.get(Calendar.DAY_OF_MONTH));
System.out.println(“時:” + now.get(Calendar.HOUR_OF_DAY));
System.out.println(“分:” + now.get(Calendar.MINUTE));
ystem.out.println(“秒:” + now.get(Calendar.SECOND));
//使用Date
Date d = new Date();
SimpleDateFormat sdf = new SimpleDateFormat(“yyyy-MM-dd HH:mm:ss”);
System.out.println(“當前時間:” + sdf.format(d));
擴展資料
JAVA中獲取當前系統時間。
import java.util.Date;
import java.text.SimpleDateFormat;
public class NowString {
public static void main(String[] args) {
SimpleDateFormat df = new SimpleDateFormat(“yyyy-MM-dd HH:mm:ss”);//設置日期格式
System.out.println(df.format(new Date()));// new Date()為獲取當前系統時間
}
}
參考資料來源:百度百科:Java
java如何把英文的日期格式改成數字化的
SimpleDateFormat sdf=new SimpleDateFormat(“yyyy-MM-dd HH:mm:ss”);
String s=sdf.format(date);//這裡的date是你獲取到的Wed Nov 30 04:17:15 CST 2011
System.out.println(s);//列印xxxx-xx-xx xx:xx:xx
java怎麼把時間轉換成”12thDecember2012,Wednesday12:12’這種形式
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
/**
*
*
* 項目名稱:Test /br
* 類名稱:Empty /br
* 類描述: /br
* 創建人:Zhou2003737 /br
* 創建時間:2013-7-23 下午04:42:14 /br
*
*/
public class Empty {
/**
* @param args
*/
public static void main(String[] args) {
Date d = new Date();
// 首先按照d(日)格式化獲取日期。
SimpleDateFormat format = new SimpleDateFormat(“d”);
String temp = format.format(d);
//判斷日期如果為1結尾且不是11則 用”dd’st’MMMMyyyy,EEEEHH:mm, yyyy”格式,設置語言環境為英語。其它類似。
if(temp.endsWith(“1”) !temp.endsWith(“11”)){
format = new SimpleDateFormat(“dd’st’MMMMyyyy,EEEEHH:mm, yyyy”,Locale.ENGLISH);
}else if(temp.endsWith(“2”) !temp.endsWith(“12”)){
format = new SimpleDateFormat(“dd’nd’MMMMyyyy,EEEEHH:mm,yyyy”,Locale.ENGLISH);
}else if(temp.endsWith(“3”) !temp.endsWith(“13”)){
format = new SimpleDateFormat(“dd’rd’MMMMyyyy,EEEEHH:mm,yyyy”,Locale.ENGLISH);
}else{
format = new SimpleDateFormat(“dd’th’MMMMyyyy,EEEEHH:mm,yyyy”,Locale.ENGLISH);
}
String result = format.format(d);
System.out.println(result);
}
}
剛寫的,測試通過。
java將英文的日期格式轉中文
實現思路:就提通過DateFormat函數,之後定義估計的時間日期格式,之後直接輸出想要的時間格式即可:
DateFormat df = new SimpleDateFormat(“yyyy年MM月dd日 HH時mm分ss秒”);
System.out.println(“當前的時間是:”+df.format(new Date()));
結果:2015年11月04日 14時24分30秒.
java如何實現各國時間格式轉換成yyyy-MM-dd HH:mm:ss時間格式?
SimpleDateFormat sdf1 = new SimpleDateFormat(“yyyy-MM-dd hh:mm:ss”);
SimpleDateFormat sdf2 = new SimpleDateFormat(“yyyy年MM月dd日 hh時mm分ss秒”);
Date d = new Date();
String timeStr = sdf1.format(d)//結果就是這種格式:2014-08-08 08:08:20
String timeStr2 = sdf2.format(d)//結果就是這種格式:2014年08月08日 08時08分20秒
在java中如何將數字的日期轉換成英文日期? 如 01/30轉換至January thirtieth.
DateFormat df1 = new SimpleDateFormat(“MMM-dd’th’, yyyy”,Locale.ENGLISH);
可以用這個格式化;
Date d = new Date();d.toGMTString();
Java中Date的toGMTString(格林威治時間)已經不推薦使用
SimpleDateFormat df = new SimpleDateFormat(“E, dd MMM yyyy HH:mm:ss z”, Locale.UK);
df.setTimeZone(new java.util.SimpleTimeZone(0, “GMT”));
return df.format(date);
效果是一樣的
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/254303.html