Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Workout the string format used for DateTime formatting

I have a string which represents a DataTime value, and I want to workout what string format was used to create the string.

For example
- Given "Wednesday 27 Jan 2010" I expect "dddd dd MMM yyyy"
- Given "2010 01 27" I expect "yyyy MM dd"

Assume that the date is close to DateTime.Now and relates to the CurrentCulture. So given that we have en-GB culture
- Given "01 01 2010" I expect "dd MM yyyy"

Is there a simple way to do this?

like image 616
Sophie88 Avatar asked Jan 27 '10 12:01

Sophie88


People also ask

What is string date/time format?

Date and time format strings A date and time format string is a string of text used to interpret data values containing date and time information. Each format string consists of a combination of formats from an available format type. Some examples of format types are day of week, month, hour, and second.

How do I format a string to mm dd yyyy?

string dateString = int. Parse("20120321"). ToString("yyyy/MM/dd");

What is the default format of DateTime?

uses a default date format to store and manipulate strings that represent dates. To specify the default date format, enter a date format in the DateTime Format String attribute in the data viewer configuration. By default, the date format is MM/DD/YYYY HH24:MI:SS.US.

What is a date and time format string?

A date and time format string defines the text representation of a DateTime or DateTimeOffset value that results from a formatting operation . It can also define the representation of a date and time value that is required in a parsing operation in order to successfully convert the string to a date and time.

How to format date and time in Excel using all formatting?

All formatting can be done also using DateTime.ToString method. There are following custom format specifiers y (year), M (month), d (day), h (hour 12), H (hour 24), m (minute), s (second), f (second fraction), F (second fraction, trailing zeroes are trimmed), t (P.M or A.M) and z (time zone).

What is the month format in datetimeformatinfo?

The Month ("M", "m") Format Specifier. The "M" or "m" standard format specifier represents a custom date and time format string that is defined by the current DateTimeFormatInfo.MonthDayPattern property. For example, the custom format string for the invariant culture is "MMMM dd".

What is the U format in datetime?

The universal full ("U") format specifier. The "U" standard format specifier represents a custom date and time format string that is defined by a specified culture's DateTimeFormatInfo.FullDateTimePattern property. The pattern is the same as the "F" pattern. However, the DateTime value is automatically converted to UTC before it is formatted.


1 Answers

The simplest thing to do is look at the reference for datetime formatting strings and working them out.

You may be able to use reflection in order to get this, or use disassembler (such as ILDASM) to find all the strings used in an assembly and guess at which ones are datetime formatting string.

If disassmbling, you can search for the days of the week and for a string starting with dddd, which should tell you how the original was constructed.

like image 167
Oded Avatar answered Oct 11 '22 07:10

Oded