date-parsing

Fastest way to parse a YYYYMMdd date in Java [closed]

馋奶兔 提交于 2019-11-28 09:18:05
When parsing a YYYYMMdd date, e.g. 20120405 for 5th April 2012, what is the fastest method? int year = Integer.parseInt(dateString.substring(0, 4)); int month = Integer.parseInt(dateString.substring(4, 6)); int day = Integer.parseInt(dateString.substring(6)); vs. int date = Integer.parseInt(dateString) year = date / 10000; month = (date % 10000) / 100; day = date % 100; mod 10000 for month would be because mod 10000 results in MMdd and the result / 100 is MM In the first example we do 3 String operations and 3 "parse to int", in the second example we do many things via modulo. What is faster?

Java 8 DateTimeFormatter two digit year 18 parsed to 0018 instead of 2018?

你离开我真会死。 提交于 2019-11-27 22:18:01
问题 With Java 8, the code below parses "18" into year "0018" instead of "2018". DateTimeFormatter formatter = DateTimeFormatter.ofPattern("M/d/y"); return LocalDate.parse(date, formatter); input date is "01/05/18". 1) why the result is "0018"? Does DateTimeFormatter not follow the 80-20 rule? 2) How to control SimpleDateFormat parse to 19xx or 20xx? talked about SimpleDateFormat.set2DigitYearStart(Date) can be used to fix the year. Is there something similar to that for DateTimeFormatter ? I was

parsing a date string from FTPClient.getModificationTime()

非 Y 不嫁゛ 提交于 2019-11-27 19:33:29
问题 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

Convert UTC to local time with NSDateFormatter

那年仲夏 提交于 2019-11-27 19:11:40
I am getting the following string from a server in my iOS app: 20140621-061250 How can I convert it to the local time? How can I define my date formatter? Is this correct? dateFormatter.dateFormat = @"YYYYMMd-HHmmss"; The question doesn't specify the nature of what you mean by converting, exactly, but the first thing you should do, regardless of the final goal, is to correctly parse the server response using a properly configured NSDateFormatter . This requires specification of the correct format string, and the time zone must be explicitly set on the formatter or it will infer it from the

How do I parse RFC 3339 datetimes with Java?

帅比萌擦擦* 提交于 2019-11-27 11:36:30
问题 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 回答1: Just found that google implemented Rfc3339

python time string does not match format

拟墨画扇 提交于 2019-11-27 08:26:55
问题 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? 回答1: %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

String-Date conversion with nanoseconds

余生长醉 提交于 2019-11-27 08:24:46
I've been struggling for a while with this piece of code for an Android app and I can't get the hang of it. I've read and tried every solution I found on stackoverflow and other places, but still no luck. What I want to do is have a function to convert a string like "17.08.2012 05:35:19:7600000" to a UTC date and a function that takes an UTC date and converts it to a string like that. String value = "17.08.2012 05:35:19:7600000"; DateFormat df = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss:SSSSSSS"); try { Date today = df.parse(value); System.out.println("Today = " + df.format(today) + " " +

How to convert a date in this format (Tue Jul 13 00:00:00 CEST 2010) to a Java Date (The string comes from an alfresco property)

随声附和 提交于 2019-11-27 04:32:12
i'm managing a date that comes from an Alfresco Properties and is in the specified (Tue Jul 13 00:00:00 CEST 2010) and i need to convert it to a Java date...i've looked around and found millions of posts for various string to date conversion form and also this page and so i tried something like this: private static final DateFormat alfrescoDateFormat = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy"); Date dataRispostaDate = alfrescoDateFormat.parse(dataRisposta); But it throws an exception.(The exception is (SSollevata un'eccezione durante la gestione della data: java.text.ParseException:

Parse a date in rails

对着背影说爱祢 提交于 2019-11-27 03:05:19
问题 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. 回答1: 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

How to parse a date string into a c++11 std::chrono time_point or similar?

邮差的信 提交于 2019-11-27 00:56:25
Consider a historic date string of format: Thu Jan 9 12:35:34 2014 I want to parse such a string into some kind of C++ date representation, then calculate the amount of time that has passed since then. From the resulting duration I need access to the numbers of seconds, minutes, hours and days. Can this be done with the new C++11 std::chrono namespace? If not, how should I go about this today? I'm using g++-4.8.1 though presumably an answer should just target the C++11 spec. Simple std::tm tm = {}; std::stringstream ss("Jan 9 2014 12:35:34"); ss >> std::get_time(&tm, "%b %d %Y %H:%M:%S"); auto