date-parsing

How can I make a DateTimeFormatter that accepts trailing junk?

别来无恙 提交于 2019-12-01 03:43:42
I'm retrofitting old some SimpleDateFormat code to use the new Java 8 DateTimeFormatter . SimpleDateFormat , and thus the old code, accepts strings with stuff in them after the date like "20130311nonsense". The DateTimeFormat I created throws a DateTimeParseException for these strings, which is probably the right thing to do, but I'd like to maintain compatibility. Can I modify my DateTimeFormat to accept these strings? I'm currently creating it like this: DateTimeFormatter.ofPattern("yyyyMMdd") bowmore Use the parse() method that takes a ParsePosition , as that one doesn't fail when it doesn

Why SimpleDateFormat(“MM/dd/yyyy”) parses date to 10/20/20128?

旧巷老猫 提交于 2019-11-30 17:06:17
I have this code: DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy"); dateFormat.setLenient(false); Date date = dateFormat.parse("10/20/20128"); and I would expect the dateFormat.parse call to throw ParseException since the year I'm providing is 5 characters long instead of 4 like in the format I defined. But for some reason even with the lenient set to false this call returns a Date object of 10/20/20128. Why is that? It doesn't make much sense to me. Is there another setting to make it even more strict? 20128 is a valid year and Java hopes the world to live that long I guess. if the

Why SimpleDateFormat(“MM/dd/yyyy”) parses date to 10/20/20128?

耗尽温柔 提交于 2019-11-30 16:38:30
问题 I have this code: DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy"); dateFormat.setLenient(false); Date date = dateFormat.parse("10/20/20128"); and I would expect the dateFormat.parse call to throw ParseException since the year I'm providing is 5 characters long instead of 4 like in the format I defined. But for some reason even with the lenient set to false this call returns a Date object of 10/20/20128. Why is that? It doesn't make much sense to me. Is there another setting to make

Convert month name to number in Delphi?

瘦欲@ 提交于 2019-11-29 16:36:30
Is there some built-in Delphi (XE2)/Windows method to convert month names to numbers 1-12; instead of looping through (TFormatSettings.)LongMonthNames[] myself? You can use IndexStr from StrUtils , returns -1 if string not found e.g. Caption := IntToStr( IndexStr(FormatSettings.LongMonthNames[7], FormatSettings.LongMonthNames) + 1); EDIT: To avoid problems with casting and case sensitivity you might use IndexText as shown: Function GetMonthNumber(Const Month:String):Integer; overload; begin Result := IndexText(Month,FormatSettings.LongMonthNames)+1 end; i can't find a method but i write one. ;

Convert timestamp string with epochal time and timezone into NSDate

☆樱花仙子☆ 提交于 2019-11-29 10:25:01
问题 I have a String in following format "/Date(573465600000-0800)/" How do I convert this to regular NSDate object? 回答1: The first part "573465600000" is the time since the Unix epoch in milliseconds , and the second part "-0800" is a time zone specification. Here is a slight modification of Parsing JSON (date) to Swift which also covers the time zone part: extension NSDate { convenience init?(jsonDate: String) { let prefix = "/Date(" let suffix = ")/" let scanner = NSScanner(string: jsonDate) //

How do I parse RFC 3339 datetimes with Java?

别说谁变了你拦得住时间么 提交于 2019-11-28 19:16:19
I'm trying to parse the date returned as a value from the HTML5 datetime input field. Try it in Opera to see an example. The date returned looks like this: 2011-05-03T11:58:01Z . I'd like to parse that into a Java Date or Calendar Object. Ideally a solution should have the following things: No external libraries (jars) Handles all acceptable RFC 3339 formats A String should be able to be easily validated to see if it is a valid RFC 3339 date Just found that google implemented Rfc3339 parser in Google HTTP Client Library https://github.com/google/google-http-java-client/blob/dev/google-http

Parsing a String into Date with DateFormat not parsing correctly

穿精又带淫゛_ 提交于 2019-11-28 14:17:30
I've been searching all over and just can't find a explanation or reason why this is happening but the parse(String) method of DateFormat just isn't parsing my String correctly. I'm trying to parse a String into the date format that is used for HTTP headers and got as far as getting the String on its own such as: Thu, 11 Nov 2010 18:34:22 GMT Which is in the format: E, d MMM yyyy HH:mm:ss z But when I use df.parse(dateStr); this is what I get out of it: Thu Nov 11 18:34:22 GMT 2010 Which is nothing like what I wanted, why is the year now after the GMT? Why is there no comma anymore? And why is

parsing a date string from FTPClient.getModificationTime()

亡梦爱人 提交于 2019-11-28 14:16:54
I am trying to parse a date string which is a modification date of a file on FTP server. Following is the code. String dateString = mFTPClient.getModificationTime(PDF_FILE_NAME_PS); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss"); Date modificationDate = dateFormat.parse(dateString.substring(dateString.indexOf(" "))); Log.v(TAG, "inside downloadservice dateString="+dateString); Log.v(TAG, "inside downloadservice modificationdate="+modificationDate.toString()); I get this in my log 05-27 10:04:20.870: V/DownloadService(751): inside downloadservice dateString=213

python time string does not match format

匆匆过客 提交于 2019-11-28 14:08:44
def deadlines(t): '''shows pretty time to deadlines''' fmt = '%a %d %m %Y %I:%M %p %Z' dt = datetime.strptime( t , fmt ) print 'dt ', repr(dt) first = 'Sun 11 May 2014 05:00 PM PDT' deadlines(first) ValueError: time data 'Sun 11 May 2014 02:00 PM PDT' does not match format ' %a %d %m %Y %I:%M %p %Z ' Whats wrong with this? %m matches months represent as a two-digit decimal (in [01, 12] ). Use %b for abbreviated month names, or %B for full month names instead: fmt = '%a %d %b %Y %I:%M %p %Z' A table showing the date format directives and their meanings can be found here . If you're having

Parse a date in rails

谁说胖子不能爱 提交于 2019-11-28 09:39:07
I have a date (Which is actually parsed from a PDF) and it could be any of the following format: MM/DD/YYYY MM/DD/YY M/D/YY October 15, 2007 Oct 15, 2007 Is there any gem or function available in rails or ruby to parse my date? Or I need to parse it using regex? BTW I'm using ruby on rails 3.2. Chris Heald You can try Date.parse(date_string) . You might also use Date#strptime if you need a specific format: > Date.strptime("10/15/2013", "%m/%d/%Y") => Tue, 15 Oct 2013 For a general solution: format_str = "%m/%d/" + (date_str =~ /\d{4}/ ? "%Y" : "%y") date = Date.parse(date_str) rescue Date