datetime-parsing

How to create DateTimeformatter with optional seconds arguments

我们两清 提交于 2019-12-19 06:57:26
问题 I am trying to create a DateTimeformatter to validate following date times: String date1 = "2017-07-06T17:25:28"; String date2 = "2017-07-06T17:25:28.1"; String date3 = "2017-07-06T17:25:28.12"; String date4 = "2017-07-06T17:25:28.123"; String date5 = "2017-07-06T17:25:28.1234"; String date6 = "2017-07-06T17:25:28.12345"; String date7 = "2017-07-06T17:25:28.123456"; String date8 = "2017-07-06T17:25:28."; I have tried the following date time formatter to validate above dates: public static

Python parsing date and find the correct locale_setting

做~自己de王妃 提交于 2019-12-18 07:19:13
问题 I have the following date string: '3 févr. 2015 14:26:00 CET' datetime.datetime.strptime('03 févr. 2015 14:26:00', '%d %b %Y %H:%M:%S') Parsing this failed with the error: ValueError: time data '03 f\xc3\xa9vr. 2015 14:26:00' does not match format '%d %b %Y %H:%M:%S' I tried to loop over all locales with locale.locale_alias : for l in locale.locale_alias: try: locale.setlocale(locale.LC_TIME, l) print l,datetime.datetime.strptime('03 févr. 2015 14:26:00', '%d %b %Y %H:%M:%S') break except

Python parsing date and find the correct locale_setting

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-18 07:18:04
问题 I have the following date string: '3 févr. 2015 14:26:00 CET' datetime.datetime.strptime('03 févr. 2015 14:26:00', '%d %b %Y %H:%M:%S') Parsing this failed with the error: ValueError: time data '03 f\xc3\xa9vr. 2015 14:26:00' does not match format '%d %b %Y %H:%M:%S' I tried to loop over all locales with locale.locale_alias : for l in locale.locale_alias: try: locale.setlocale(locale.LC_TIME, l) print l,datetime.datetime.strptime('03 févr. 2015 14:26:00', '%d %b %Y %H:%M:%S') break except

Parse 'Date & Time' string in Javascript which are of custom format

自作多情 提交于 2019-12-18 03:17:28
问题 I have to parse a date and time string of format "2015-01-16 22:15:00". I want to parse this into JavaScript Date Object. Any help on this? I tried some jquery plugins, moment.js, date.js, xdate.js. Still no luck. 回答1: With moment.js you can create a moment object using the String+Format constructor: var momentDate = moment('2015-01-16 22:15:00', 'YYYY-MM-DD HH:mm:ss'); Then, you can convert it to JavaScript Date Object using toDate() method: var jsDate = momentDate.toDate(); 回答2: A better

Java 8 DateTimeFormatter parsing for optional fractional seconds of varying significance

混江龙づ霸主 提交于 2019-12-17 19:32:45
问题 My MCVE (as a TestNG unit test): public class MyDateTimeFormatterTest { private static final String BASE_PATTERN = "yyyy/MM/dd HH:mm:ss"; private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern(BASE_PATTERN + "[.SSSSSSSSS]"); private static final LocalDateTime TEST_INPUT = LocalDateTime.of(2015, 5, 4, 12, 34, 56, 123456789); @DataProvider(name = "test-cases") public Iterator<Object[]> getTestCases() { return Arrays.asList(testFor("", ChronoUnit.SECONDS), testFor(".SSS",

Parse Date String in Java [duplicate]

风格不统一 提交于 2019-12-17 17:23:06
问题 This question already has answers here : Converting ISO 8601-compliant String to java.util.Date (28 answers) Java - SimpleDateFormat formatter to return epoch time with milliseconds [duplicate] (6 answers) Closed last year . I have date in the format "yyyy-MM-dd'T'HH:mm:ss.sssZ". for example the date is "2018-07-17T09:59:51.312Z". I am using the below code to parse the String in Java. String date="2018-07-17T09:59:51.312Z"; SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd

Natural/Relative days in Python

谁说胖子不能爱 提交于 2019-12-17 09:19:38
问题 I'd like a way to show natural times for dated items in Python. Similar to how Twitter will show a message from "a moment ago", "a few minutes ago", "two hours ago", "three days ago", etc. Django 1.0 has a "humanize" method in django.contrib. I'm not using the Django framework, and even if I were, it's more limited than what I'd like. Please let me (and generations of future searchers) know if there is a good working solution already. Since this is a common enough task, I imagine there must

How to create a .NET DateTime from ISO 8601 format

陌路散爱 提交于 2019-12-16 22:23:29
问题 I've found how to turn a DateTime into an ISO 8601 format, but nothing on how to do the reverse in C#. I have 2010-08-20T15:00:00Z , and I want to turn it into a DateTime object. I could separate the parts of the string myself, but that seems like a lot of work for something that is already an international standard. 回答1: This solution makes use of the DateTimeStyles enumeration, and it also works with Z. DateTime d2 = DateTime.Parse("2010-08-20T15:00:00Z", null, System.Globalization

How to set Z as timezone in SimpleDateFormat

泪湿孤枕 提交于 2019-12-14 03:35:29
问题 Code sample: SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z"); System.out.println(dateFormat.getTimeZone()); System.out.println(dateFormat.parse(time)); // dateFormat.setTimeZone(TimeZone.getTimeZone("Asia/Kolkata")); I don't want to use the commented section. Zone should be set based on IST that I am giving in the input string: String time ="2018-04-06 16:13:00 IST"; Current machine zone is: America/New_York . How should I get zone changes to IST based on z?

How do I convert DateTime to another format?

送分小仙女□ 提交于 2019-12-14 03:25:10
问题 From a weather feed I'm getting the data for dates in the form of 2012-05-17 . How do I convert that to Thursday May 17th form? 回答1: Parse the string into a JavaScript Date object. Format the Date object however you like. See also: Why does Date.parse give incorrect results? and How to format a JavaScript date questions. 回答2: How about this: var originalDateTime = '2012-05-17', splitedDatetime = originalDateTime.split('0'), date = new Date(), date.setFullYear(splitedDatetime[0]