本文整理了Java中java.text.SimpleDateFormat.set2DigitYearStart()
方法的一些代码示例,展示了SimpleDateFormat.set2DigitYearStart()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。SimpleDateFormat.set2DigitYearStart()
方法的具体详情如下:
包路径:java.text.SimpleDateFormat
类名称:SimpleDateFormat
方法名:set2DigitYearStart
[英]Sets the date which is the start of the one hundred year period for two-digit year values.
When parsing a date string using the abbreviated year pattern yy, SimpleDateFormat must interpret the abbreviated year relative to some century. It does this by adjusting dates to be within 80 years before and 20 years after the time the SimpleDateFormat instance was created. For example, using a pattern of MM/dd/yy, an instance created on Jan 1, 1997 would interpret the string "01/11/12"as Jan 11, 2012 but interpret the string "05/04/64" as May 4, 1964. During parsing, only strings consisting of exactly two digits, as defined by java.lang.Character#isDigit(char), will be parsed into the default century. Any other numeric string, such as a one digit string, a three or more digit string, or a two digit string that isn't all digits (for example, "-1"), is interpreted literally. So using the same pattern, both "01/02/3" and "01/02/003" are parsed as Jan 2, 3 AD. Similarly, "01/02/-3" is parsed as Jan 2, 4 BC.
If the year pattern does not have exactly two 'y' characters, the year is interpreted literally, regardless of the number of digits. So using the pattern MM/dd/yyyy, "01/11/12" is parsed as Jan 11, 12 A.D.
[中]设置两位数年份值的百年期开始日期。
当使用缩写年模式yy解析日期字符串时,SimpleDataFormat必须解释相对于某个世纪的缩写年。它通过将日期调整为创建SimpleDataFormat实例之前80年和之后20年内来实现这一点。例如,使用MM/dd/yy模式,1997年1月1日创建的实例将字符串“01/11/12”解释为2012年1月11日,但将字符串“05/04/64”解释为1964年5月4日。在解析过程中,只有由java定义的两位数字组成的字符串。lang.Character#isDigit(char),将解析为默认的世纪。任何其他数字字符串,如一位字符串、三位或更多位字符串或并非全部数字的两位字符串(例如“-1”),都会按字面解释。因此,使用相同的模式,“01/02/3”和“01/02/003”都被解析为公元前3年1月2日。同样,“01/02/-3”被解析为公元前4年1月2日。
如果年份模式没有精确的两个“y”字符,则不管位数多少,年份都会按字面解释。因此,使用MM/dd/yyyy模式,“01/11/12”被解析为公元12年1月11日。
代码示例来源:origin: neo4j/neo4j
public Date parse( String input ) throws ParseException
{
format.set2DigitYearStart( Y2K_START_DATE );
return format.parse( input );
}
代码示例来源:origin: commons-httpclient/commons-httpclient
dateParser = new SimpleDateFormat(format, Locale.US);
dateParser.setTimeZone(TimeZone.getTimeZone("GMT"));
dateParser.set2DigitYearStart(startDate);
} else {
dateParser.applyPattern(format);
代码示例来源:origin: org.apache.commons/commons-lang3
private void validateSdfFormatFdpParseEquality(final String format, final Locale locale, final TimeZone tz, final DateParser fdp, final Date in, final int year, final Date cs) throws ParseException {
final SimpleDateFormat sdf = new SimpleDateFormat(format, locale);
sdf.setTimeZone(tz);
if (format.equals(SHORT_FORMAT)) {
sdf.set2DigitYearStart( cs );
}
final String fmt = sdf.format(in);
try {
final Date out = fdp.parse(fmt);
assertEquals(locale.toString()+" "+in+" "+ format+ " "+tz.getID(), in, out);
} catch (final ParseException pe) {
if (year >= 1868 || !locale.getCountry().equals("JP")) {// LANG-978
throw pe;
}
}
}
代码示例来源:origin: robovm/robovm
dateParser.set2DigitYearStart(startDate);
代码示例来源:origin: robovm/robovm
private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException {
ObjectInputStream.GetField fields = stream.readFields();
int version = fields.get("serialVersionOnStream", 0);
Date date;
if (version > 0) {
date = (Date) fields.get("defaultCenturyStart", new Date());
} else {
date = new Date();
}
set2DigitYearStart(date);
formatData = (DateFormatSymbols) fields.get("formatData", null);
pattern = (String) fields.get("pattern", "");
}
}
代码示例来源:origin: org.apache.logging.log4j/log4j-core
private void validateSdfFormatFdpParseEquality(final String format, final Locale locale, final TimeZone tz, final DateParser fdp, final Date in, final int year, final Date cs) throws ParseException {
final SimpleDateFormat sdf = new SimpleDateFormat(format, locale);
sdf.setTimeZone(tz);
if (format.equals(SHORT_FORMAT)) {
sdf.set2DigitYearStart( cs );
}
final String fmt = sdf.format(in);
try {
final Date out = fdp.parse(fmt);
assertEquals(locale.toString()+" "+in+" "+ format+ " "+tz.getID(), in, out);
} catch (final ParseException pe) {
if (year >= 1868 || !locale.getCountry().equals("JP")) {// LANG-978
throw pe;
}
}
}
代码示例来源:origin: stackoverflow.com
localSimpleDateFormat.get().set2DigitYearStart(startDate);
代码示例来源:origin: haraldk/TwelveMonkeys
private static void update50YearWindowIfNeeded() {
// Avoid class synchronization
long next = sNext50YearWindowChange;
if (next < System.currentTimeMillis()) {
// Next check in one day
next += DateUtil.DAY;
sNext50YearWindowChange = next;
Date startDate = new Date(next - (50l * DateUtil.CALENDAR_YEAR));
//System.out.println("next test: " + new Date(next) + ", 50 year start: " + startDate);
synchronized (HTTP_RFC850_FORMAT) {
HTTP_RFC850_FORMAT.set2DigitYearStart(startDate);
}
synchronized (HTTP_ASCTIME_FORMAT) {
HTTP_ASCTIME_FORMAT.set2DigitYearStart(startDate);
}
}
}
代码示例来源:origin: stackoverflow.com
SimpleDateFormat sdf = new SimpleDateFormat("yy/MM/dd", Locale.US);
Calendar cal = Calendar.getInstance(Locale.US);
cal.set(1900, 0, 1);
sdf.set2DigitYearStart(cal.getTime());
System.out.println(sdf.parse("16/07/23"));
代码示例来源:origin: stackoverflow.com
SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yy");
String aDate = "03/17/40";
Calendar cal = Calendar.getInstance();
cal.clear();
cal.set(Calendar.YEAR, 2000);
dateFormat.set2DigitYearStart(cal.getTime());
System.out.println(dateFormat.get2DigitYearStart());
System.out.println(dateFormat.parse(aDate));
代码示例来源:origin: jamesagnew/hapi-fhir
dateParser.set2DigitYearStart(localStartDate);
final ParsePosition pos = new ParsePosition(0);
final Date result = dateParser.parse(v, pos);
代码示例来源:origin: resteasy/Resteasy
dateParser.set2DigitYearStart(startDate);
代码示例来源:origin: at.bestsolution.eclipse/com.ibm.icu.base
/**
* Sets the 100-year period 2-digit years will be interpreted as being in
* to begin on the date the user specifies.
* @param startDate During parsing, two digit years will be placed in the range
* <code>startDate</code> to <code>startDate + 100 years</code>.
* @stable ICU 2.0
*/
public void set2DigitYearStart(Date startDate) {
((java.text.SimpleDateFormat)dateFormat).set2DigitYearStart(startDate);
}
代码示例来源:origin: at.bestsolution.efxclipse.eclipse/com.ibm.icu.base
/**
* Sets the 100-year period 2-digit years will be interpreted as being in
* to begin on the date the user specifies.
* @param startDate During parsing, two digit years will be placed in the range
* <code>startDate</code> to <code>startDate + 100 years</code>.
* @stable ICU 2.0
*/
public void set2DigitYearStart(Date startDate) {
((java.text.SimpleDateFormat)dateFormat).set2DigitYearStart(startDate);
}
代码示例来源:origin: org.neo4j.app/neo4j-server
public Date parse( String input ) throws ParseException
{
format.set2DigitYearStart( Y2K_START_DATE );
return format.parse( input );
}
代码示例来源:origin: org.refcodes/refcodes-date
/**
* {@inheritDoc}
*
* @deprecated as it is not considered to be thread safe.
*/
@Deprecated
@Override
public void set2DigitYearStart( Date startDate ) {
super.set2DigitYearStart( startDate );
}
代码示例来源:origin: stackoverflow.com
Calendar cal = Calendar.getInstance();
cal.set(Calendar.YEAR, 2000);
SimpleDateFormat inFormat = new SimpleDateFormat("dd/MM/yy");
inFormat.set2DigitYearStart(cal.getTime());
SimpleDateFormat outFormat = new SimpleDateFormat("MM/dd/yyyy");
try {
// Old Date is 10/12/03
String value = outFormat.format(inFormat.parse("10/12/03"));
System.out.println(value);
} catch (ParseException e) {
e.printStackTrace();
}
代码示例来源:origin: jdereg/java-util
public void set2DigitYearStart(Date date)
{
getDateFormat(_format).set2DigitYearStart(date);
}
}
代码示例来源:origin: stackoverflow.com
SimpleDateFormat format = new SimpleDateFormat( "dd.MM.yyyy" );
SimpleDateFormat editFormat = new SimpleDateFormat( "dd.MM.yy" );
final Date startDate = new Date( 0 );//01.01.1970
instance.setTime(startDate);
editFormat.set2DigitYearStart( instance.getTime() );
DefaultFormatterFactory factory = new DefaultFormatterFactory(
new DatePickerFormatter(new DateFormat[] {format}),
new DatePickerFormatter(new DateFormat[] {format}),
new DatePickerFormatter(new DateFormat[] {editFormat})
);
picker.getEditor().setFormatterFactory(factory);
代码示例来源:origin: net.sf.jt400/jt400
synchronized SimpleDateFormat getDateFormatter(Integer centuryDigit)
{
if (centuryDigit == null) return getDateFormatter();
else
{
Date d = getStartDateForCentury(centuryDigit.intValue());
getDateFormatter();
dateFormatter_.set2DigitYearStart(d);
return dateFormatter_;
}
}
内容来源于网络,如有侵权,请联系作者删除!