datetime-parsing

How to solve the error convert String date from xml file to an int format?

£可爱£侵袭症+ 提交于 2019-12-13 22:41:59
问题 I also find myself facing the date problem today, I extracted the date from an xml file in string format but when I try to convert it into an int format I have an error. This is a part of my code : DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); Document doc = dBuilder.parse(inputFile); doc.getDocumentElement().normalize(); System.out.println("Root element :" + doc.getDocumentElement().getNodeName()); NodeList nList = doc.getElementsByTagName("top"); for (int j=0; j<= inputFile

Count number between two date (C#, CultureInfo)

孤街醉人 提交于 2019-12-13 09:34:58
问题 I trying to get Number between 2 dates : DateTime base; .... base = DateTime.ParseExact(pos[13], "dd/MM/yyyy HH:mm:ss", CultureInfo.InvariantCulture); //example base = 2014-06-21 17:00:00 DateTime col_N; //then some for loop col_N = DateTime.ParseExact(pos[k], "dd/MM/yyyy HH:mm:ss", CultureInfo.InvariantCulture); //example col_N = 2014-06-22 00:00:00 To get days between I'm doing like below: int date_diff = (col_N - base).Days; but it return me 0 . Also, when I checked: string diff_dat2 =

Correctly parse date string with timezone information

房东的猫 提交于 2019-12-12 10:55:36
问题 I'm receiving a formatted date string like this via the pivotal tracker API: "2012/06/05 17:42:29 CEST" I want to convert this string to a UTC datetime object, it looks like python-dateutil does not recognize that timezone, pytz doesn't know it either. I fear my best bet is to replace CEST in the string with CET, but this feels very wrong. Is there any other way to parse summer time strings to UTC datetime objects I couldn't find? pytz.timezone('CEST') # -> pytz.exceptions

Formatting ISO 8601 in Java 7

怎甘沉沦 提交于 2019-12-11 07:28:23
问题 I have date format like this 2016-11-25T09:29:10.588+01:00 I want to convert this to milliseconds and later while printing I have to again convert milliseconds to " yyyy-MM-dd HH:mm:ss.SSS " this format. static FastDateFormat alarmDateFormat = FastDateFormat.getInstance("yyyy-MM-dd HH:mm:ss.SSS"); DateFormat df1 = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss.SSSXXX"); df1.setTimeZone(TimeZone.getTimeZone("UTC")); String string1 = "2016-11-25T09:29:10.588+01:00"; Date result1 = df1.parse

Parse String for unknown TemporalAccessor

六眼飞鱼酱① 提交于 2019-12-11 06:26:40
问题 I'm getting a request parameter with unknown temporal (date, time or timestamp in ISO format) and want to parse it into a java.time.temporal.TemporalAccessor : LocalDate when the string represents a date like "2018-02-28" or LocalDateTime when the string represents a timestamp like "2018-02-28T11:20:00" The following attempt results into DateTimeParseException : TemporalAccessor dt = DateTimeFormatter.ISO_DATE_TIME.parseBest(str, LocalDateTime::from, LocalDate::from); Deciding on the length

How to convert a given time (String) to a LocalTime?

喜夏-厌秋 提交于 2019-12-10 22:59:30
问题 I will be asking a user to enter a specific time: 10AM, 12:30PM, 2:47PM, 1:09AM, 5PM, etc. I will be using a Scanner to get the user's input. How can I parse/convert that String to a LocalTime object? Is there any built-in function in Java that will allow me to do that? 回答1: Just use a java.time.format.DateTimeFormatter : DateTimeFormatter parser = DateTimeFormatter.ofPattern("h[:mm]a"); LocalTime localTime = LocalTime.parse("10AM", parser); Explaining the pattern: h : am/pm hour of day (from

Java Instant.parse on Date java 8

久未见 提交于 2019-12-10 21:53:04
问题 I have some legacy KML documents which includes a time stamp entry. Why is the below date not valid when using Instant to parse? Both methods are suppose to parse ISO 8601 formatted dates. String dateString = "2017-12-04T08:06:60Z" Using java.time.Instant.parse(dateString) throws an error "DateTimeParseException Text 2017-12-04T08:06:60Z could not be parsed at index 0." However, when using Date myDate = javax.xml.bind.DatatypeConverter.parseDateTime( dateString ) myDate is parsed correctly...

Trying to parse a datetime in PDT to a ZonedDateTime representation

那年仲夏 提交于 2019-12-10 18:55:09
问题 How should I parse this datetime value that is in the PDT timezone? 06/24/2017 07:00 AM (PDT) I want to maintain the timezone so that I can then represent the time in other timezones depending on the website visitors preferences. I tried using ZonedDateTime but I get a parse error: java.time.ZonedDateTime.parse("06/24/2017 07:00 AM (PDT)") The error is: java.time.format.DateTimeParseException: Text '06/24/2017 07:00 AM (PDT)' could not be parsed at index 0 at java.time.format

java.time DateTimeFormatter parsing with flexible fallback values

会有一股神秘感。 提交于 2019-12-10 13:43:54
问题 I am trying to port some code from joda time to java time. JodaTime had the possibility to specify a fallback value for the year like this parser.withDefaultYear((new DateTime(DateTimeZone.UTC)).getYear()).parseDateTime(text); Regardless how the parser looks (if it includes a year or not), this will be parsed. java.time has become much more stricter there. Even though there is the DateTimeFormatterBuilder.parseDefaulting() method, which allows you to specify fallbacks, this only works if that

Getting error : String was not recognized as a valid DateTime in c#

浪尽此生 提交于 2019-12-09 01:54:30
问题 Getting error like : An unhandled exception of type 'System.FormatException' occurred in mscorlib.dll Additional information: String was not recognized as a valid DateTime. I am using this code : string datetime = DateTime.Parse(encrypt[1]); or string datetime = Convert.ToDatetime(encrypt[1]); encrypt is a string array In encrypt[1] I am not sure which format will come in string . i have trace some time come dd/MM/yyyy and sometime MM/dd/yyyy or MM-dd-yyyy or dd-MM-yyyy . I am not sure about