简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM