import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
class test {
public static void main(String args[]) {
Calendar cal = new GregorianCalendar();
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd") ;
System.out.println(cal.toString());
System.out.println(cal.get(Calendar.YEAR)+"년 "+cal.get (Calendar.MONTH)+"월 "+cal.get(Calendar.DAY_OF_MONTH)+"일");
//1년전
cal.add(Calendar.YEAR, -1);
String date1 = sdf.format(cal.getTime());
System.out.println(date1) ;
//현재일
String strDate = "";
SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd");
long currentTime = System.currentTimeMillis();
strDate = df.format(new Date(currentTime));
System.out.println(strDate);
//한줄 현재일
String strDate =new SimpleDateFormat("yyyyMMdd").format(new Date( System.currentTimeMillis() ));
//시간
String ap = "";
if(1 == cal.get(Calendar.AM_PM)) {
ap = "PM" ;
}else {
ap = "AM" ;
}
System.out.println(ap + " " + cal.get(Calendar.HOUR) + ":" + cal.get(Calendar.MINUTE) + ":" + cal.get(Calendar.SECOND) + ":" + cal.get(Calendar.MILLISECOND));
}
}
-----------------------
SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd");
String now = df.format(new Date());
int strDate = Integer.parseInt(now.substring(0,4));
Calendar cal = Calendar.getInstance();
int year = cal.get(Calendar.YEAR);
'Java' 카테고리의 다른 글
[Java] JavaMail 패키지 (0) | 2010.12.07 |
---|---|
[Java] BASE64Encoder와 Seed 암호화 (1) | 2010.11.22 |
[Java] 웹개발 로드맵 (0) | 2010.07.06 |
[Java] File (0) | 2010.07.02 |
[Java] Thread.yeild (0) | 2010.06.25 |