本文整理汇总了C#中System.Globalization.PersianCalendar.ToDateTime方法的典型用法代码示例。如果您正苦于以下问题:C# PersianCalendar.ToDateTime方法的具体用法?C# PersianCalendar.ToDateTime怎么用?C# PersianCalendar.ToDateTime使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Globalization.PersianCalendar
的用法示例。
在下文中一共展示了PersianCalendar.ToDateTime方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: getMiladiFromPersian
public static System.DateTime getMiladiFromPersian(string perDate)
{
int year = int.Parse(perDate.Substring(0, perDate.IndexOf("/")));
perDate = perDate.Substring(perDate.IndexOf("/") + 1);
int month = int.Parse(perDate.Substring(0, perDate.IndexOf("/")));
perDate = perDate.Substring(perDate.IndexOf("/") + 1);
int day = int.Parse(perDate);
System.Globalization.PersianCalendar persianCalendar = new System.Globalization.PersianCalendar();
return persianCalendar.ToDateTime(year, month, day, 0, 0, 0, 0);
}
示例2: TestUpperLimits
public void TestUpperLimits()
{
PersianCalendar cal = new PersianCalendar();
Assert.Throws<ArgumentOutOfRangeException>(() =>
{
cal.ToDateTime(9378, 10, 14, 0, 0, 0, 0);
});
Assert.Throws<ArgumentOutOfRangeException>(() =>
{
cal.GetYear(new DateTime(622, 3, 21));
});
}
示例3: ConvertPersianToGregorianDate
public DateTime ConvertPersianToGregorianDate(string persianDate)
{
var englishDigitPersianDate = FConvert.ToEnglishDigit(persianDate);
var tokens = englishDigitPersianDate.Split('/');
//validation
if (tokens.Length != 3)
throw new ArgumentException("Persian date must have 3 tokens");
var year = tokens[0];
var month = tokens[1];
var day = tokens[2];
//correcting date with format dd/mm/yyyy
if (month.Length == 2 && day.Length == 4 && year.Length == 2)
{
var temp = day;
day = year;
year = temp;
}
if (year.Length != 2 && year.Length != 4)
throw new ArgumentException("Persian year must be 2 or 4 digits");
if (month.Length > 2 || day.Length > 2)
throw new ArgumentException("Persian month/day must have 2 digit maximum");
if (year.Length == 2)
year = "13" + year;
var yearValue = Convert.ToInt32(year);
var monthValue = Convert.ToInt32(month);
var dayValue = Convert.ToInt32(day);
if (monthValue < 1 || monthValue > 12)
throw new ArgumentException("month must be between 1 and 12");
if (dayValue < 1 || dayValue > 31)
throw new ArgumentException("day must be between 1 and 31");
var pc = new PersianCalendar();
return pc.ToDateTime(yearValue, monthValue, dayValue, 0, 0, 0, 0);
}
示例4: GetMiladiDate
public static DateTime GetMiladiDate(this string persianDate)
{
string[] strDate = persianDate.Split('/');
int y, m, d;
if (strDate[0].Length == 4)
{
y = int.Parse(strDate[0]);
m = int.Parse(strDate[1]);
d = int.Parse(strDate[2]);
}
else
{
y = int.Parse(strDate[2]);
m = int.Parse(strDate[1]);
d = int.Parse(strDate[0]);
}
var jC = new PersianCalendar();
return jC.ToDateTime(y, m, d, 0, 0, 0, 0);
}
示例5: TestCalendarConversion
public void TestCalendarConversion()
{
PersianCalendar cal = new PersianCalendar();
int i = 0;
while (i < s_dates.Length)
{
DateTime date = new DateTime(s_dates[i + 3], s_dates[i + 4], s_dates[i + 5]);
Assert.True(cal.GetYear(date) == s_dates[i], String.Format("Calculated Persian Year {0} not equal the expected year {1}", cal.GetYear(date), s_dates[i]));
Assert.True(cal.GetMonth(date) == s_dates[i + 1], String.Format("Calculated Persian Month {0} not equal the expected Month {1}", cal.GetMonth(date), s_dates[i + 1]));
Assert.True(cal.GetDayOfMonth(date) == s_dates[i + 2], String.Format("Calculated Persian Day {0} not equal the expected Day {1}", cal.GetDayOfMonth(date), s_dates[i + 2]));
DateTime result = cal.ToDateTime(s_dates[i], s_dates[i + 1], s_dates[i + 2], 0, 0, 0, 0);
Assert.True(result.Year == s_dates[i + 3], String.Format("Calculated Gregorian Year {0} not equal the expected year {1}", result.Year, s_dates[i + 3]));
Assert.True(result.Month == s_dates[i + 4], String.Format("Calculated Gregorian Month {0} not equal the expected Month {1}", result.Month, s_dates[i + 4]));
Assert.True(result.Day == s_dates[i + 5], String.Format("Calculated Gregorian Day {0} not equal the expected Day {1}", result.Day, s_dates[i + 5]));
i += 6;
}
}
示例6: ConvertToGeorgian
public static DateTime? ConvertToGeorgian(object obj)
{
if (obj.IsNull())
{
return null;
}
string farsiDate = obj.ToString();
if (Regex.IsMatch(farsiDate, PersianDateRegex))
{
string[] split = farsiDate.Split('/');
int year = Int32.Parse(split[0]);
int month = Int32.Parse(split[1]);
int day = Int32.Parse(split[2]);
var calendar = new PersianCalendar();
return calendar.ToDateTime(year, month, day, 0, 0, 0, 0);
}
else
{
return null;
}
}
示例7: ShamsiTogregorian
public DateTime ShamsiTogregorian(DateTime date)
{
PersianCalendar pc = new PersianCalendar();
GregorianCalendar gcalendar = new GregorianCalendar();
DateTime eDate = pc.ToDateTime(
gcalendar.GetYear(date),
gcalendar.GetMonth(date),
gcalendar.GetDayOfMonth(date),
gcalendar.GetHour(date),
gcalendar.GetMinute(date),
gcalendar.GetSecond(date), 0);
return eDate;
}
示例8: ShamsiToMiladi
private DateTime ShamsiToMiladi(String date_str)
{
string[] jdate = date_str.Split(new char[] {Convert.ToChar("\\")});
PersianCalendar pd = new PersianCalendar();
DateTime dt = pd.ToDateTime(Convert.ToInt32(jdate[0]), Convert.ToInt32(jdate[1]), Convert.ToInt32(jdate[2]), 0, 0, 0, 0);
return dt;
}
示例9: IsValidPersianDate
public bool IsValidPersianDate(string source)
{
var isValid = true;
try
{
var tokens = FConvert.ToEnglishDigit(source).Split('/');
var pc = new PersianCalendar();
pc.ToDateTime(Convert.ToInt32(tokens[0]), Convert.ToInt32(tokens[1]), Convert.ToInt32(tokens[2]), 0, 0, 0, 0);
}
catch
{
isValid = false;
}
return isValid;
}
示例10: GregorianDate
public static System.DateTime GregorianDate(int year, int month, int day, int hour, int minute, int second, int milisecond)
{
var p = new PersianCalendar();
return p.ToDateTime(year, month, day, hour, minute, second, milisecond);
}
开发者ID:omidnasri,项目名称:Implement-a-Generic-Repository-and-a-Unit-of-Work-Class,代码行数:5,代码来源:KDateTime.cs
示例11: GetDateTime
private static DateTime? GetDateTime(string persianDateString)
{
var calendar = new PersianCalendar();
string[] dateArray = persianDateString.Split("/".ToCharArray());
try
{
int year = int.Parse(dateArray[0]);
int month = int.Parse(dateArray[1]);
int day = int.Parse(dateArray[2]);
return calendar.ToDateTime(year, month, day, 0, 0, 0, 0);
}
catch
{ /* ! it means value is null ! */
return null;
}
}
示例12: p_PersianToMiladi
private static DateTime p_PersianToMiladi(string persianDate, string PersianTime = null)
{
Regex re = new Regex(@"(\d{2,4})/(\d{1,2})/(\d{1,2})");
Regex revRegex = new Regex(@"(\d{1,2})/(\d{1,2})/(\d{2,4})");
Match m;
int Year = 0;
int Month = 0;
int Day = 0;
if (re.IsMatch(persianDate))
{
m = re.Match(persianDate);
Year = int.Parse(m.Groups[1].Value);
Month = int.Parse(m.Groups[2].Value);
Day = int.Parse(m.Groups[3].Value);
}
else if (revRegex.IsMatch(persianDate))
{
m = revRegex.Match(persianDate);
Year = int.Parse(m.Groups[3].Value);
Month = int.Parse(m.Groups[2].Value);
Day = int.Parse(m.Groups[1].Value);
}
CheckDateRange(Month, Day);
string[] arrPersianTime = new[] { "0", "0" };
if (!string.IsNullOrWhiteSpace(PersianTime))
arrPersianTime = PersianTime.Split(':');
PersianCalendar calendar = new PersianCalendar();
return calendar.ToDateTime(Year, Month, Day, arrPersianTime[0].ToInt32(), arrPersianTime[1].ToInt32(), 0, 0);
}
示例13: ToDateTime
public DateTime ToDateTime()
{
PersianCalendar persianCalendar = new PersianCalendar();
return persianCalendar.ToDateTime(this.Year, this.Month, this.Day, 0, 0, 0, 0);
}
示例14: GetChristianDateTime
public static DateTime GetChristianDateTime(string _Fdate)
{
_Fdate = _Fdate.Trim().Replace(':', '/').Replace('-', '/').Replace(' ', '/');
var dateArray = new string[6];
if (_Fdate.Length <= 10)
{
_Fdate = _Fdate + "/0/0/0";
}
dateArray = _Fdate.Split('/');
PersianCalendar pcalendar = new PersianCalendar();
GregorianCalendar gcalendar = new GregorianCalendar();
DateTime eDate = pcalendar.ToDateTime(
gcalendar.GetYear(new DateTime(int.Parse(dateArray[0]), 1, 1)),
gcalendar.GetMonth(new DateTime(1395, int.Parse(dateArray[1]), 1)),
gcalendar.GetDayOfMonth(new DateTime(1395, 1, int.Parse(dateArray[2]))),
gcalendar.GetHour(new DateTime(1395, 1, 1, int.Parse(dateArray[3]), 0, 0)),
gcalendar.GetMinute(new DateTime(1395, 1, 1, 1, int.Parse(dateArray[4]), 0)),
gcalendar.GetSecond(new DateTime(1395, 1, 1, 1, 1, int.Parse(dateArray[5]))), 0);
return eDate;
}