r.r
r.r

Reputation: 7153

How to convert DataTime Value in specific Culture with c#?

i have a DateTime value = 3/24/2011 6:25:29 PM saved i public DateTime propertie LastChange how can i convert it in German Datetime Form?? like: 3/24/2011 18:25:29?

Upvotes: 4

Views: 16581

Answers (4)

MaLio
MaLio

Reputation: 2530

Just substitute your culture

    System.DateTime now = System.DateTime.Now;

    System.Console.WriteLine(now);

    System.Globalization.CultureInfo culture = 
             new System.Globalization.CultureInfo(1031); // de-DE
    System.Console.WriteLine(now.ToString(culture));

Upvotes: 0

hyp
hyp

Reputation: 1380

You can pass a CultureInfo as a IFormatProvider: http://msdn.microsoft.com/en-us/library/system.iformatprovider%28v=VS.90%29.aspx

Upvotes: 0

Fadrian Sudaman
Fadrian Sudaman

Reputation: 6465

Just use ToString and specify your custom format string like below

LastChange.ToString("M/dd/yyyy HH:mm:ss")

Upvotes: 3

SLaks
SLaks

Reputation: 887453

You can write

date.ToString(new CultureInfo("de-DE"))

Upvotes: 4

Related Questions