2-digit-year

Localize string from `MonthDay` or `YearMonth` classes in java.time? [duplicate]

自闭症网瘾萝莉.ら 提交于 2019-11-29 12:51:36
This question already has an answer here: How to format YearMonth and MonthDay depending on a Locale? 3 answers The java.time classes built into Java 8 and later offer the MonthDay and YearMonth classes. Their toString and parse methods use standard ISO 8601 formats ( --MM-DD & YYYY-MM ), which is wise. For presentation to humans, the standard formats may not be suitable. Is there anyway to generate an automatically localized string to represent the values in objects of either MonthDay or YearMonth ? For example, in the United States users might typically want MM/DD for month-day and MM/YY for

How to parse string dates with 2-digit year?

房东的猫 提交于 2019-11-29 09:04:18
I need to parse strings representing 6-digit dates in the format yymmdd where yy ranges from 59 to 05 (1959 to 2005). According to the time module docs, Python's default pivot year is 1969 which won't work for me. Is there an easy way to override the pivot year, or can you suggest some other solution? I am using Python 2.7. Thanks! I'd use datetime and parse it out normally. Then I'd use datetime.datetime.replace on the object if it is past your ceiling date -- Adjusting it back 100 yrs.: import datetime dd = datetime.datetime.strptime(date,'%y%m%d') if dd.year > 2005: dd = dd.replace(year=dd

Converting a year from 4 digit to 2 digit and back again in C#

穿精又带淫゛_ 提交于 2019-11-28 23:32:39
问题 My credit card processor requires I send a two-digit year from the credit card expiration date. Here is how I am currently processing: I put a DropDownList of the 4-digit year on the page. I validate the expiration date in a DateTime field to be sure that the expiration date being passed to the CC processor isn't expired. I send a two-digit year to the CC processor (as required). I do this via a substring of the value from the year DDL. Is there a method out there to convert a four-digit year

Force 4-digit-year in localized strings generated from `DateTimeFormatter.ofLocalized…` in java.time

♀尐吖头ヾ 提交于 2019-11-28 02:04:36
The DateTimeFormatter class in java.time offers three ofLocalized… methods for generating strings to represent values that include a year. For example, ofLocalizedDate . Locale l = Locale.US ; DateTimeFormatter f = DateTimeFormatter.ofLocalizedDate( FormatStyle.SHORT ).withLocale( l ); LocalDate today = LocalDate.now( ZoneId.of( "America/Chicago" ) ); String output = today.format( f ); For the locales I have seen, the year is only two digits in the shorter FormatStyle styles. How to let java.time localize yet force the years to be four digits rather than two? I suspect the Answer lies in

How to parse string dates with 2-digit year?

雨燕双飞 提交于 2019-11-27 22:57:13
问题 I need to parse strings representing 6-digit dates in the format yymmdd where yy ranges from 59 to 05 (1959 to 2005). According to the time module docs, Python's default pivot year is 1969 which won't work for me. Is there an easy way to override the pivot year, or can you suggest some other solution? I am using Python 2.7. Thanks! 回答1: I'd use datetime and parse it out normally. Then I'd use datetime.datetime.replace on the object if it is past your ceiling date -- Adjusting it back 100 yrs.

How to change the base date for parsing two letter years with Java 8 DateTimeFormatter?

余生颓废 提交于 2019-11-27 09:06:20
If I use a pattern like d/M/yy for creating a Java 8 DateTimeFormatter (e.g. using DateTimeFormatter.ofPattern(pattern); (which I will only use for parsing, not formatting), it will interpret all two-letter years as 20xx, e.g. parsing a string like 13/5/99 to be interpreted as 2099-05-13 , which in my case is wrong (it was meant to be in the year 1999). In my application, I'm trying to parse dates from OCR'd documents, which could e.g. still be from the 90ies, so having the old SimpleDateFormat behavior of interpreting the date to be within 80 years before and 20 years after the current date

Force 4-digit-year in localized strings generated from `DateTimeFormatter.ofLocalized…` in java.time

元气小坏坏 提交于 2019-11-26 22:06:16
问题 The DateTimeFormatter class in java.time offers three ofLocalized… methods for generating strings to represent values that include a year. For example, ofLocalizedDate. Locale l = Locale.US ; DateTimeFormatter f = DateTimeFormatter.ofLocalizedDate( FormatStyle.SHORT ).withLocale( l ); LocalDate today = LocalDate.now( ZoneId.of( "America/Chicago" ) ); String output = today.format( f ); For the locales I have seen, the year is only two digits in the shorter FormatStyle styles. How to let java

Parsing string to local date doesn't use desired century

吃可爱长大的小学妹 提交于 2019-11-26 21:01:45
I am using this DateTimeFormatter: DateTimeFormatter.ofPattern("ddMMYY") I want to parse the string 150790 and I got this error: Unable to obtain LocalDate from TemporalAccessor: {DayOfMonth=15, MonthOfYear=7, WeekBasedYear[WeekFields[MONDAY,4]]=2090},ISO of type java.time.format.Parsed Obviously, I want to get the following TemporalAccessor : {DayOfMonth=15, MonthOfYear=7, WeekBasedYear=1990} Do you know why I got the year 2090 instead of 1990? Thanks for your help Since this question is really about new java.time -package and NOT SimpleDateFormat I will cite following relevant section : Year

How to change the base date for parsing two letter years with Java 8 DateTimeFormatter?

我是研究僧i 提交于 2019-11-26 17:48:29
问题 If I use a pattern like d/M/yy for creating a Java 8 DateTimeFormatter (e.g. using DateTimeFormatter.ofPattern(pattern); (which I will only use for parsing, not formatting), it will interpret all two-letter years as 20xx, e.g. parsing a string like 13/5/99 to be interpreted as 2099-05-13 , which in my case is wrong (it was meant to be in the year 1999). In my application, I'm trying to parse dates from OCR'd documents, which could e.g. still be from the 90ies, so having the old