Vladyslav  Kurkotov
Vladyslav Kurkotov

Reputation: 505

How to generate culture specific date pattern from c#

My goal is to synchronize the date displaying, generated both by c# and JavaScript.

For c# displaying I am using "d" .ToString("{0:d}") pattern.

For javascript I am using kendo datetime picker. This widget accepts the dateTime format in which the value will be shown:

@(Html.Kendo().DatePicker()
    .Name("dateFrom")
    .Format("dd.MM.yyyy"))

What I want is to generate culture specific string pattern from c# that I will pass to .Format() method.

I know that I can do this manually by using resx files. But is there a way for doing this automatically?

Upvotes: 0

Views: 76

Answers (1)

Jürgen Röhr
Jürgen Röhr

Reputation: 941

The CultureInfo class offers all types of date- and numeric formats. So you could use

var ci = CultureInfo.CurrentUICulture; 
var format = ci.DateTimeFormat.ShortDatePattern;

Hope this helps.

Upvotes: 2

Related Questions