mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
修复FastDatePrinter处理YY错误问题
This commit is contained in:
parent
0662e77c0a
commit
2c4ddba2ab
@ -967,7 +967,12 @@ public class FastDatePrinter extends SimpleDateBasic implements DatePrinter {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void appendTo(final Appendable buffer, final Calendar calendar) throws IOException {
|
public void appendTo(final Appendable buffer, final Calendar calendar) throws IOException {
|
||||||
mRule.appendTo(buffer, calendar.getWeekYear());
|
int weekYear = calendar.getWeekYear();
|
||||||
|
if (mRule instanceof TwoDigitYearField) {
|
||||||
|
// issue#3641
|
||||||
|
weekYear %= 100;
|
||||||
|
}
|
||||||
|
mRule.appendTo(buffer, weekYear);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -0,0 +1,58 @@
|
|||||||
|
package org.dromara.hutool.core.date.format;
|
||||||
|
|
||||||
|
import org.dromara.hutool.core.date.DateUtil;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.TimeZone;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
|
public class FastDateFormatTest {
|
||||||
|
private static final TimeZone timezone = TimeZone.getTimeZone("Etc/Utc");
|
||||||
|
|
||||||
|
private static FastDateFormat getHutoolInstance(final String pattern) {
|
||||||
|
return FastDateFormat.getInstance(pattern, timezone);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void yearTest() {
|
||||||
|
final Date date = DateUtil.date(0L);
|
||||||
|
|
||||||
|
assertEquals(
|
||||||
|
"1970-01-01 00:00:00",
|
||||||
|
getHutoolInstance("yyyy-MM-dd HH:mm:ss").format(date)
|
||||||
|
);
|
||||||
|
|
||||||
|
assertEquals(
|
||||||
|
"1970-01-01 00:00:00",
|
||||||
|
getHutoolInstance("YYYY-MM-dd HH:mm:ss").format(date)
|
||||||
|
);
|
||||||
|
|
||||||
|
assertEquals(
|
||||||
|
"1970",
|
||||||
|
getHutoolInstance("YYYY").format(date)
|
||||||
|
);
|
||||||
|
|
||||||
|
assertEquals(
|
||||||
|
"70",
|
||||||
|
getHutoolInstance("yy").format(date)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void weekYearTest() {
|
||||||
|
final Date date = DateUtil.date(0L);
|
||||||
|
|
||||||
|
assertEquals(
|
||||||
|
"70",
|
||||||
|
new SimpleDateFormat("YY").format(date)
|
||||||
|
);
|
||||||
|
|
||||||
|
assertEquals(
|
||||||
|
"70",
|
||||||
|
getHutoolInstance("YY").format(date)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user