음력, 음력 -> 양력 변환" href="http://blog.naver.com/levin01/100004872718">양력 -> 음력, 음력 -> 양력 변환
Calendar클래스(GregorianCalendar)를 이용한 달력 출력하기
에릭에반스와 켄트백이 만든 돈과 시간 관련 라이브러리
http://www.opengamma.com/blog/2011/jsr-310-experience
yyyyMMddHHmmss
http://joda-time.sourceforge.net/
http://timeandmoney.sourceforge.net/
java.text.DateFormat
java.text.SimpleDateFormat
import java.util.Calendar;
import java.util.Date;
import java.util.SimpleTimeZone;
public static Date parseDate(String dateStr) {
SimpleDateFormat fmt = new SimpleDateFormat("yyyyMMdd");
SimpleTimeZone timeZone = new SimpleTimeZone(9 * 60 * 60 * 1000, "KST");
fmt.setTimeZone(timeZone);
try {
return fmt.parse(dateStr);
} catch (ParseException e) {
return null;
}
}
public static String getDateString(Date date, String format) {
// 테스트
if (date == null) {
return "";
}
SimpleDateFormat dateFormat = new SimpleDateFormat(format);
SimpleTimeZone timeZone = new SimpleTimeZone(9 * 60 * 60 * 1000, "KST");
dateFormat.setTimeZone(timeZone);
Calendar cal = dateFormat.getCalendar();
cal.setTime(date);
return dateFormat.format(cal.getTime());
}
/**
* 현재 시스템 날짜(yyyyMMdd HH:mm:ss.SSS) 값을 얻어온다.
* @return ymd
*/
public static String getTimeSSS() {
long currentTimes = System.currentTimeMillis();
String ymd = new SimpleDateFormat("yyyyMMdd HH:mm:ss.SSS").format(new Date(currentTimes));
return ymd;
}
import java.util.Calendar;
import java.util.GregorianCalendar;
public class WeekdayTest {
public static void main(String args[]){
boolean b1 = isMatchedWeekday("20080114", Calendar.MONDAY);
boolean b2 = isMatchedWeekday("20080105", Calendar.SATURDAY);
boolean b3 = isMatchedWeekday("20080107", Calendar.MONDAY);
System.out.println(b1);
System.out.println(b2);
System.out.println(b3);
}
public static boolean isMatchedWeekday(String date, int weekday){
int year = Integer.parseInt(date.substring(0,4));
int month = Integer.parseInt(date.substring(4,6))-1;
int day = Integer.parseInt(date.substring(6,8));
Calendar c = new GregorianCalendar();
c.set(year,month,day);
return (weekday ==c.get(Calendar.DAY_OF_WEEK));
}
}
static final String DAY_FORAMT = "yyyy-MM-dd";
static final String TIME_FORAMT = "yyyy-MM-dd HH:mm:ss";
@Test
public void dateTest() throws Exception {
Date date = DateUtils.parseDate("1850-01-01 00:00:00", new String[]{TIME_FORAMT});
int count = 200 * 365;
System.out.println("Expected print out => Actual print out");
do {
String actualDateString = DateFormatUtils.format(date, TIME_FORAMT);
String expectedDateString = DateFormatUtils.format(date, DAY_FORAMT) + " 00:00:00";
if (!actualDateString.equals(expectedDateString)) {
System.out.println(expectedDateString + " => " + actualDateString);
}
assertTrue(actualDateString.equals(expectedDateString));
date = DateUtils.addDays(date,1);
date = DateUtils.truncate(date, Calendar.DATE);
} while (count-- > 0);
http://java.sun.com/javase/tzupdater_README.html
http://java.sun.com/javase/timezones/