Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# DateTime, is this method regional setting safe?

Tags:

c#

datetime

I am using the following method to serialize a date as a string

private const string DateFormatString = "dd.MM.yyyy HH:mm:ss";
string LastsuccessfuldownloadDateTime = DateTime.Now.AddDays(-91).ToString(DateFormatString);

Is this the safest way to ensure that the string always gets serialized in this format?

Update on one server I have this running its completely getting the fields wrong.

like image 697
JL. Avatar asked Apr 21 '10 10:04

JL.


People also ask

What is the full name of C?

In the real sense it has no meaning or full form. It was developed by Dennis Ritchie and Ken Thompson at AT&T bell Lab. First, they used to call it as B language then later they made some improvement into it and renamed it as C and its superscript as C++ which was invented by Dr.

What do you mean by C?

" " C is a computer programming language. That means that you can use C to create lists of instructions for a computer to follow. C is one of thousands of programming languages currently in use.

What is C language used for?

C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...


1 Answers

I would use explicit invariant for serialization to avoid any unexpected gotchas. You may also want to think whether you need UTC or not; for example:

string LastsuccessfuldownloadDateTime = DateTime.UtcNow.AddDays(-91).ToString(
    DateFormatString, CultureInfo.InvariantCulture);
like image 112
Marc Gravell Avatar answered Sep 28 '22 07:09

Marc Gravell