我有一个用户插入波斯语DateTime的表单文本框 我想将波斯日期转换为日期时间以保存在sql中 谢谢你的答案
答案 0 :(得分:4)
CodeProject上有很多文章你可能会觉得有用:
Persian DateTime
Farsi Library - Working with Dates, Calendars, and DatePickers
在CodeProject中搜索“波斯语”,我打赌你会发现很多有用的东西。
答案 1 :(得分:4)
将DateTime.Parse与波斯语CultureInfo:
一起使用var input = "8/30/2009 03:32";
var datetime = DateTime.Parse(input, CultureInfo.CreateSpecificCulture("fa-IR"));
答案 2 :(得分:2)
您可以使用此代码:
using System.Globalization;
PersianCalendar pCalendar = new PersianCalendar();
DateTime a = DateTime.Now;
int year = pCalendar.GetYear(a);
int month = pCalendar.GetMonth(a);
int day = pCalendar.GetDayOfMonth(a);
int hour = pCalendar.GetHour(a);
int min = pCalendar.GetMinute(a);
int sec = pCalendar.GetSecond(a);
int mSec = int.Parse(pCalendar.GetMilliseconds(a).ToString());
MessageBox.Show(year + "/" + month + "/" + day);// persian date
DateTime dateTime = pCalendar.ToDateTime(year,month,day,hour,min,sec,mSec);
MessageBox.Show(dateTime.ToShortDateString());//DateTime
答案 3 :(得分:1)
System.Globalization.PersianCalendar pCalendar = new System.Globalization.PersianCalendar();
int year = pCalendar.GetYear(MiladyDateTime);
int month = pCalendar.GetMonth(MiladyDateTime);
int day = pCalendar.GetDayOfMonth(MiladyDateTime);
int hour = pCalendar.GetHour(MiladyDateTime);
int min = pCalendar.GetMinute(MiladyDateTime);
int sec = pCalendar.GetSecond(MiladyDateTime);
int mSec = int.Parse(pCalendar.GetMilliseconds(MiladyDateTime).ToString());
int era = pCalendar.GetEra(MiladyDateTime);
string Date = new DateTime(year, month, day, hour, min, sec, mSec).ToString();