import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import com.documentum.fc.common.DfTime;
import com.documentum.fc.common.IDfTime;
public class SimpleDateFormatTest {
public static void main(String args[]){
DateFormat formatInValid=new SimpleDateFormat("mm/dd/yyyy");
DateFormat formatValid=new SimpleDateFormat("MM/dd/yyyy");
Date givenDate = null;
Date currentDate = null;
try {
givenDate =(Date)formatInValid.parse("01/16/2013");
currentDate=(Date)formatInValid.parse(new DfTime().asString(IDfTime.DF_TIME_PATTERN2));// 02/01/2013
System.out.println("Is 01/16/2013 after 02/01/2013 ?");
System.out.println("Expecting result : false");
System.out.println("Actual output of SimpleDateFormat mm/dd/yyyy (mm is the lower case): "+givenDate.after(currentDate));
givenDate =(Date)formatValid.parse("01/16/2013");
currentDate=(Date)formatValid.parse(new DfTime().asString(IDfTime.DF_TIME_PATTERN2));
System.out.println("Actual output of SimpleDateFormat MM/dd/yyyy (MM is the upper case): "+givenDate.after(currentDate));
} catch (ParseException e) {
//Todo
}
}
}
SimpleDateFormat is Case Sensitive
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.