Date 類: 最基礎的日期時間類
Calender類: 相對於Date更加強大的時間類
GregorianCalendar類: 提供處理日期的方法
DateFormat類: 可以接受字符串輸入 輸出
SimpleDateFormat類: 功能更強大的日期時間格式化類
java
public String GetCurTime()//獲得當前時間
{
Date now=new Date();
return now
}
public String GetCurDate()//獲得當前日期
{
Calendar cal=Calendar
return cal
}
calendar = Calendar
calendar
calendar = Calendar
calendar
Calendar calendar = Calendar
long nowTime = calendar
String strDate =
SimpleDateFormat sDateFormat = new SimpleDateFormat(
Date sDate = sDateFormat
Date dt_in
boolean bShowTimePart_in
@return String 格式化後的日期格式
*/
public String DoFormatDate(java
if (bShowTimePart_in)
return (new SimpleDateFormat(
else
return (new SimpleDateFormat(
}
public void testLocale(){
Locale defaultLocale = Locale
System
System
System
System
System
System
System
}
DateTime date = new DateTime(new Date()
獲取時分秒的方法
package ceshi;
import java
import java
import java
public class Ceshi {
public static void main(String[] args) throws ParseException {
SimpleDateFormat CeshiFmt
SimpleDateFormat CeshiFmt
SimpleDateFormat CeshiFmt
SimpleDateFormat CeshiFmt
SimpleDateFormat CeshiFmt
SimpleDateFormat CeshiFmt
Date now=new Date();
System
System
System
System
System
System
}
}
公元
一年中的第
獲取兩個日期間的所有日期
public static GregorianCalendar[] getBetweenDate(String d
{
Vector<GregorianCalendar> v=new Vector<GregorianCalendar>();
SimpleDateFormat sdf=new SimpleDateFormat(
GregorianCalendar gc
gc
gc
do{
GregorianCalendar gc
v
gc
}while(!gc
return v
}
public static void main(String[] args) throws Exception {
// TODO Auto
GregorianCalendar[] ga=getBetweenDate(
for(GregorianCalendar e:ga)
{
System
+(e
e
}
}
From:http://tw.wingwit.com/Article/program/Java/hx/201311/27009.html