Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DateTime Format Problem To Get Same Format

Tags:

c#

datetime

I have some questions about using datetime format.

In one part of project,client pc send their datetime to server. we need to get those datetime in same format like dd/MM/yyyy.

However,client pc use variety of date format,so,they send variety of datetime format like this.for eg,

dd-MM-yyyy,dd/MM/yyyy,MM-dd-yyyy,MM/dd/yyyy

How can I solve this problem?

like image 354
Indi Avatar asked Feb 14 '11 08:02

Indi


People also ask

How do I convert a DateTime to a specific format?

The ToString() method of the DateTime class is used to convert a DateTime date object to string format. The method takes a date format string that specifies the required string representation.

How do I fix the date format in Excel?

Select the cells you want to format. Press CTRL+1. In the Format Cells box, click the Number tab. In the Category list, click Date, and then choose a date format you want in Type.

What is TZ DateTime format?

What is T between date and time? The T is just a literal to separate the date from the time, and the Z means “zero hour offset” also known as “Zulu time” (UTC). If your strings always have a “Z” you can use: SimpleDateFormat format = new SimpleDateFormat( “yyyy-MM-dd'T'HH:mm:ss).

What is the default format of DateTime?

DATETIME type is a date and time combination, and stores data in YYYY-MM-DD HH:MM:SS format.


1 Answers

The absolute best way is to not treat date values as strings. They should to the greatest extent possible be treated as DateTime values. When doing that, all issues related to formatting disappears. If you have a client where the user enters date format in their local style, convert it to a DateTime directly after input, and then send the DateTime value into the system.

If you still need to exchange date information in string format, always stick to a standardized format (such as ISO 8601).

like image 96
Fredrik Mörk Avatar answered Sep 30 '22 13:09

Fredrik Mörk