import java.util.*; class Test { Calendar cal; public Test() { cal = Calendar.getInstance(); System.out.println(cal.get(Calendar.WEEK_OF_YEAR));//周次 } public static void main(String[] args) { new Test(); } } 其它的方法楼主自己找找看吧
Letter Date or Time Component Presentation Examples G Era designator Text AD y Year Year 1996; 96 M Month in year Month July; Jul; 07 w Week in year Number 27 W Week in month Number 2 D Day in year Number 189 d Day in month Number 10 F Day of week in month Number 2 E Day in week Text Tuesday; Tue a Am/pm er Text PM H Hour in day (0-23) Number 0 k Hour in day (1-24) Number 24 K Hour in am/pm (0-11) Number 0 h Hour in am/pm (1-12) Number 12 m Minute in hour Number 30 s Second in minute Number 55 S Millisecond Number 978 z Time zone General time zone Pacific Standard Time; PST; GMT-08:00 Z Time zone RFC 822 time zone -0800 对其中的w做些处理能够满足你的要求
GregorianCalendar today=new GregorianCalendar (); today.set(2005,11,31); int count=today.get(Calendar.WEEK_OF_YEAR); //这样便获得了2005年又多少周及当前周属于今年的第几个周count是2005年的最后一天所以你应该明白了
class Test
{
Calendar cal;
public Test()
{
cal = Calendar.getInstance();
System.out.println(cal.get(Calendar.WEEK_OF_YEAR));//周次
}
public static void main(String[] args)
{
new Test();
}
}
其它的方法楼主自己找找看吧
看看Calendar
如果有时间,看看Date
就会明白了
foramter.format(new Date());其中yyyyMMddHHmmss,可以按需要随意组合。java doc理由详细说明。
import java.util.*;
import java.text.*;
public class FormatDate {
public static void main(String[] args) {
Date now = new Date(); DateFormat defaultFormat = DateFormat.getDateInstance();
DateFormat shortFormat = DateFormat.getDateInstance(DateFormat.SHORT);
DateFormat mediumFormat = DateFormat.getDateInstance(DateFormat.MEDIUM);
DateFormat longFormat = DateFormat.getDateInstance(DateFormat.LONG);
DateFormat fullFormat = DateFormat.getDateInstance(DateFormat.FULL);
String defaultDate = defaultFormat.format(now);
String shortDate = shortFormat.format(now);
String mediumDate = mediumFormat.format(now);
String longDate = longFormat.format(now);
String fullDate = fullFormat.format(now); System.out.println("(Default) Today :" + defaultDate);
System.out.println("(SHORT) Today : " + shortDate);
System.out.println("(MEDIUM) Today :" + mediumDate);
System.out.println("(LONG) Today : " + longDate);
System.out.println("(FULL) Today : " + fullDate);
}
} 运行结果为:
D:\javamail>java FormatDate
(Default) Today :2003-6-15
(SHORT) Today : 03-6-15
(MEDIUM) Today :2003-6-15
(LONG) Today : 2003年6月15日
(FULL) Today : 2003年6月15日 星期日
G Era designator Text AD
y Year Year 1996; 96
M Month in year Month July; Jul; 07
w Week in year Number 27
W Week in month Number 2
D Day in year Number 189
d Day in month Number 10
F Day of week in month Number 2
E Day in week Text Tuesday; Tue
a Am/pm er Text PM
H Hour in day (0-23) Number 0
k Hour in day (1-24) Number 24
K Hour in am/pm (0-11) Number 0
h Hour in am/pm (1-12) Number 12
m Minute in hour Number 30
s Second in minute Number 55
S Millisecond Number 978
z Time zone General time zone Pacific Standard Time; PST; GMT-08:00
Z Time zone RFC 822 time zone -0800
对其中的w做些处理能够满足你的要求
today.set(2005,11,31);
int count=today.get(Calendar.WEEK_OF_YEAR);
//这样便获得了2005年又多少周及当前周属于今年的第几个周count是2005年的最后一天所以你应该明白了