datetime-format

How to parse date format?

空扰寡人 提交于 2019-12-04 02:40:51
问题 In one of the webservices my application is consuming, I encountered the following DateTime format. "/Date(1395780377459)/" Is this some standard date format? If so, how to parse this into DateTime object? EDIT: Thanks for the comments. So "/Date(1395780377459)/" corresponds to GMT: Tue, 25 Mar 2014 20:46:17 GMT . I was wondering how to parse this in .net. Tried: string test = "/Date(1395780377459)/"; var datestring = test.Substring(6).TrimEnd(')','/'); var date = new DateTime(long.Parse

Convert SimpleDateFormat to DateTimeFormatter

落花浮王杯 提交于 2019-12-04 01:26:22
So when trying to replace some legacy code using SimpleDateFormat and Date, to use java.time.DateTimeFormatter and LocalDate I ran into a problem. The two date formats are not equivalent. At this point I must say I know the two date types are not the same but the scenario I am in means I never care about the time aspect so can ignore it. public Date getDate(String value) { SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy"); try { return dateFormat.parse(value); } catch (ParseException e) { return null; } } public LocalDate getLocalDate(String value) { DateTimeFormatter formatter

Output of times (AM/PM) changed in Windows 10 when using DateTime.ToString(“tt”)

断了今生、忘了曾经 提交于 2019-12-03 23:52:33
I recently upgraded to windows 10 - and I'm now seeing some rather unexpected changes in the output of a date when using the "tt" format specifier. Here's some code that demonstrates the issue: using System.IO; using System; using System.Globalization; using System.Threading.Tasks; class Program { static void Main() { var cultures = new string[] {null, "en-NZ", "en-US", "en-AU", "en-GB"}; foreach (var culture in cultures) { if (culture != null) { var c = CultureInfo.GetCultureInfo(culture); System.Threading.Thread.CurrentThread.CurrentCulture = System.Threading.Thread.CurrentThread

Getting a short day name

♀尐吖头ヾ 提交于 2019-12-03 22:36:35
I was wondering on how to write a method that will return me a string which will contain the short day name, example: public static string GetShortDayName(DayOfWeek day) now if i call: string monday = GetShortDayName(DayOfWeek.Monday); I will get back "mo" if culture is en, or "lu" if culture is at example it. You can use DateTimeFormatInfo.AbbreviatedDayNames . For example: string[] names = culture.DateTimeFormat.AbbreviatedDayNames; string monday = names[(int) DayOfWeek.Monday]; The closest you can get is use a custom date and time format string - specifically ddd . This will return an

Where are the Java 8 DateTimeFormatters constants defined?

試著忘記壹切 提交于 2019-12-03 16:24:28
I am looking at the DateTimeFormatter class and I was wondering where are the constants like "M" , "EEE" and "YY" etc are defined. More specifically there should be code like this somewhere given a ChronoField and TextStyle , it should return the DateTimeFormatter string snippet e.g. (ChronoField.MONTH_OF_YEAR, TextStyle.SHORT) should map to the string "MMM" After some source digging, I found out that these are pre-defined in a private static final Map , called FIELD_MAP , which is a member of the DateTimeFormatBuilder class: /** Map of letters to fields. */ private static final Map<Character,

Representing Fraction of Second with ISO 8601:2004

血红的双手。 提交于 2019-12-03 16:01:06
The following is the definition of IS0 8601:2004 standard. It says that the fraction of second can be represented with one to six digits. Can I use all the 6 digits for representing the fraction of a second? Are the following Representation correct, if I use 6 digits for representing fraction of a second? 1ms -- 001000 10ms -- 010000 100ms -- 100000 {Extended Time Format} (32 bytes) YYYY-MM-DDThh:mm:ss.sTZD YYYY = Year 0000 to 9999 MM = Month 01 to 12 DD = Day 01 to 31 T = special separator T hh = Hour 00 to 23 mm = Minute 00 to 59 ss = Second 00 to 59 s = one to six digits representing a

How can I convert date time format string used by C# to the format used by moment.js?

你说的曾经没有我的故事 提交于 2019-12-03 11:13:19
C# uses string like that 'dd MMMM yyyy HH:mm' to define format the date and time should be displayed in. Equivalent of that in momentjs is 'DD MMMM YYYY HH:mm' . Is there some function that can covert one format definition into the other regardless of what (legal) combination of format specifiers source format contains? Basically what I want is: function toMomentJsFormatDefinition(cSharpFormatDefinition) { // should convert all format strings described here https://msdn.microsoft.com/en-us/library/8kb3ddd4%28v=vs.110%29.aspx } console.log(toMomentJsFormatDefinition('dd MMMM yyyy HH:mm')); //

how do I parse an iso 8601 date (with optional milliseconds) to a struct tm in C++?

与世无争的帅哥 提交于 2019-12-03 09:53:25
I have a string which should specify a date and time in ISO 8601 format, which may or may not have milliseconds in it, and I am wanting to get a struct tm from it as well as any millisecond value that may have been specified (which can be assumed to be zero if not present in the string). What would be involved in detecting whether the string is in the correct format, as well as converting a user-specified string into the struct tm and millisecond values? If it weren't for the millisconds issue, I could probably just use the C function strptime() , but I do not know what the defined behavior of

java.time.DateTimeFormatter : Need ISO_INSTANT that always renders milliseconds

江枫思渺然 提交于 2019-12-03 06:13:36
I'm trying to cleanup a mix of various code around datetime management to only Java 8 java.time namespace. Right now I have a small issue with the default DateTimeFormatter for Instant . The DateTimeFormatter.ISO_INSTANT formatter only shows milliseconds when they are not equal to zero. The epoch is rendered as 1970-01-01T00:00:00Z instead of 1970-01-01T00:00:00.000Z . I made a unit test to explain the problem and how we need to final dates to be compared one to each other. @Test public void java8Date() { DateTimeFormatter formatter = DateTimeFormatter.ISO_INSTANT; String epoch, almostEpoch,

Store Date Format in elasticsearch

一个人想着一个人 提交于 2019-12-03 05:39:15
问题 I met a problem when I want to add one datetime string into Elasticsearch. The document is below: {"LastUpdate" : "2013/07/24 00:00:00"} This document raised an error which is "NumberFormatException" [For input string: \"20130724 00:00:00\"] I know that I can use the Date Format in Elasticsearch, but I don't know how to use even I read the document on the website. {"LastUpdate": { "properties": { "type": "date", "format": "yyyy-MM-dd"} } } and {"LastUpdate": { "type": "date", "format": "yyyy