Пример работы с датами

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package ru.golodnyj.lection.time;
import java.util.Date;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.text.SimpleDateFormat;
import java.text.Format;
import java.text.DateFormat;
/**
* Date: 06.08.2009
* Time: 8:51:11
*
* @author golodnyj
* @version 0.1
*/
public class ShowTime {
public static void main(String[] args) {
System.out.println("Now : " + System.currentTimeMillis());
Date date = new Date();
System.out.println("Date :" + date);
// date.getDate();
// date.getDay();
// date.getHours();
// date.getMinutes();
// date.getMonth();
// date.getSeconds();
// date.getTimezoneOffset();
// date.getYear();
// date.getTime();
// date.after(new Date());
// date.before(new Date());
Calendar c = new GregorianCalendar();
System.out.println("Calendar :"
+ c.getTime());
System.out.println("Calendar.DATE :"+ Calendar.DATE);
System.out.println("Calendar.DAY_OF_MONTH :"+ Calendar.DAY_OF_MONTH);
System.out.println("Calendar.DAY_OF_YEAR :"+ Calendar.DAY_OF_YEAR);
System.out.println("Calendar.DAY_OF_YEAR :"+ Calendar.YEAR);
System.out.println("Current month : " + c.get(Calendar.MONTH));
System.out.println("Current date: " + c.get(Calendar.DATE));
Format f = DateFormat.getDateInstance(); //MEDUIM
System.out.println("FormatedDate : " + f.format(date));
SimpleDateFormat formatter = new SimpleDateFormat();
System.out.println("FormatedDate : " + formatter.format(c.getTime()));
System.out.println("FormatedDate : " + formatter.format(date));
SimpleDateFormat formatterNew = new SimpleDateFormat("dd.MM.yyyy");
System.out.println("FormatedDate : " + formatterNew.format(c.getTime()));
System.out.println("FormatedDate : " + formatterNew.format(date));
}
}