سؤال

I have a date binded in a asp.net repeater control

<%# Eval("PublishedDate") %>

I have two cultures: English and Arabic.

currently I am getting this [29/04/35 07:00:00 م] date in arabic but i want following [5 يناير 2014] format

and in english I am getting [3/1/2014 7:00:00 PM] but i want following format [January 5, 2014]

هل كانت مفيدة؟

المحلول

Use resources by creating 2 local resource files one for English {PageName}.en.resx and the other for Arabic {PageName}.ar.resx and put the format in.

Steps:

  • Create 2 local resources for the page, for example Default.aspx.en.resx and Default.aspx.ar.resx
  • Add DateFormat item in each resource, in Arabic resource file DateFormat ==> d MMM yyyy and in English resource file DateFormat ==> MMM d,yyyy
  • Change the binding expression in ASPX to be like this <%# Eval("PublishedDate", etLocalResourceObject("DateFormat").ToString()) %>
  • last thing is to change Culture of the page to tell ASP.NET engine which local resource use

نصائح أخرى

Have you looked into System.Globalization.CultureInfo and the associated format classes?

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top