使用此代码我强制文本框只接受波斯语单词:
private void CommenttxtBox_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
{
System.Globalization.CultureInfo Language =
new System.Globalization.CultureInfo("Fa-ir");
InputLanguage.CurrentInputLanguage = InputLanguage.FromCulture(Language);
}
并在计时器上添加一个英文日历:
private void ShowTime_Tick(object sender, EventArgs e)
{
ShowTimelbl.Text = DateTime.Now.ToString();
}
无论如何都要让日期时间显示波斯语(jalali)时间?
答案 0 :(得分:3)
您需要创建PersianCalendar
类的实例。
它可以将任何DateTime
值转换为波斯语的月,月和日。
var persianCalendar = new PersianCalendar();
var dateTime = DateTime.Now;
var year = persianCalendar.GetYear(dateTime);
var month = persianCalendar.GetMonth(dateTime);
var day = persianCalendar.GetDayOfMonth(dateTime);
var date = string.Format("{0}/{1}/{2}", year, month, day);
然后向用户显示此date
字符串。
答案 1 :(得分:3)
您可以将CultureInfo
传递给ToString
方法:
DateTime.Now.ToString(new System.Globalization.CultureInfo("Fa-ir"));
结果:
"03/22/2016 12:51:28 ب.ظ"
答案 2 :(得分:1)
private void ShowTime_Tick(object sender, EventArgs e)
{
var PersianCalender = new PersianCalendar();
var datetime = DateTime.Now;
var year = PersianCalender.GetYear(datetime);
var month = PersianCalender.GetMonth(datetime);
var day = PersianCalender.GetDayOfMonth(datetime);
var hour = PersianCalender.GetHour(datetime);
var minute = PersianCalender.GetMinute(datetime);
var second = PersianCalender.GetSecond(datetime);
var datetimeshow = string.Format
("{0}:{1}:{2} {3}/{4}/{5}", hour, minute, second, year, month, day);
ShowTimelbl.Text = datetimeshow;
}
答案 3 :(得分:0)
using System.Globalization;
DateTime dt = DateTime.Now;
PersianCalendar jc = new PersianCalendar();
private string[] weeks = new string[] {"شنبه", "یکشنبه", "دوشنبه", "سه شنبه", "چهارشنبه", "پنجشنبه", "جمعه" };
private string[] months = new string[] { "فروردین", "اردیبهشت", "خرداد", "تیر","مرداد", "شهریور", "مهر", "آبان", "آذر", "دی", "بهمن", "اسفند" };
private string[] days = new string[] { "یک", "دو", "سه", "چهار", "پنج", "شش", "هفت", "هشت", "نه", "ده", "یازده", "دوازده", "سیزده", "چهارده", "پانزده", "شانزده", "هفده", "هجده", "نوزده", " بیست", "بیست و یک", "بیست و دوم", "بیست و سوم", "بیست و چهارم", "بیست و پنجم", "بیست و ششم", "بیست و هفتم", "بیست و هشتم", "بیست و نهم", "سی" };
private void Persian_Date_Load(object sender, EventArgs e)
{
lbl.Text="امروز"+"\r\n"+ jc.GetYear(DateTime.Now) + "/" + jc.GetMonth(DateTime.Now) + "/" + jc.GetDayOfMonth(DateTime.Now)+"\r\n"+ jc.GetYear(DateTime.Now).ToString()+" "+weeks[(int)jc.GetDayOfWeek(DateTime.Now)+1] +" "+ days[jc.GetDayOfMonth(DateTime.Now)-1]+ " " + months[jc.GetMonth(DateTime.Now) - 1];
}