???????Java??SimpleDateFormat????????????
???????????? ???????[ 2013/6/13 10:41:46 ] ????????
?????????????????JDK????????????SimpleDateFormat??DateFormat??????????????????
????SimpleDateFormat?????DateFormat????DateFormat?ж????????protected????? Calendar??????calendar????????Calendar??????????????????????????Jdk???????????????????????????????????????????????????
??????format??????????????δ???
private StringBuffer format(Date date?? StringBuffer toAppendTo??
FieldDelegate delegate) {
// Convert input date to time field list
calendar.setTime(date);
boolean useDateFormatSymbols = useDateFormatSymbols();
for (int i = 0; i < compiledPattern.length; ) {
int tag = compiledPattern[i] >>> 8;
int count = compiledPattern[i++] & 0xff;
if (count == 255) {
count = compiledPattern[i++] << 16;
count |= compiledPattern[i++];
}
switch (tag) {
case TAG_QUOTE_ASCII_CHAR:
toAppendTo.append((char)count);
break;
case TAG_QUOTE_CHARS:
toAppendTo.append(compiledPattern?? i?? count);
i += count;
break;
default:
subFormat(tag?? count?? delegate?? toAppendTo?? useDateFormatSymbols);
break;
}
}
return toAppendTo;
}
????calendar.setTime(date)???????????calendar?????calendar???????????subFormat?????????????????????????????????£???????????????£???????????????????SimpleDateFormat?????????????format??????
???????1????format???????????calendar?????Ρ?
?????ж??????
???????2?????У?????????calendar??
???????ж????
???????1????????????calendar??????????????????????????????2?????·?????????????????calendar?????????????????????????????????
???????????format???????????????????????????calendar???????????????subFormat?????????????????????????????????????????????????????????????·?????????????????????ж???
??????????????????????????????????--???????????????????????????????????£?????????????á?????????????????????????????????????????????????????????????????????Ρ?format?????????й????и????SimpleDateFormat??calendar??Σ?????????????????
??????????????????????????????????????????????:
????1?????д????????????????????????μ???????????????????
????2???????????£????????????????????????????????
????3???????????????????????????????????????
?????????????
????1???????????????????
package com.peidasoft.dateformat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class DateUtil {
public static String formatDate(Date date)throws ParseException{
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
return sdf.format(date);
}
public static Date parse(String strDate) throws ParseException{
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
return sdf.parse(strDate);
}
}
?????????????????SimpleDateFormat ?????????????????????????????????????????????????????ж???????????????????????????????????????????????£????????????????????????????
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11