-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDateMethods.cs
More file actions
22 lines (22 loc) · 793 Bytes
/
DateMethods.cs
File metadata and controls
22 lines (22 loc) · 793 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
using System;
using System.Globalization;
namespace SadrTools.CommonTools.Utility
{
public static class DateMethods
{
/// <summary>
/// تبدیل به تاریخ شمسی
/// </summary>
/// <param name="date">تاریخ</param>
/// <param name="seprator">جدا کننده</param>
/// <returns>تاریخ شمسی</returns>
public static string ToPersianDate(DateTime date, char seprator = '/')
{
PersianCalendar pc = new PersianCalendar();
int year = pc.GetYear(date);
int month = pc.GetMonth(date);
int day = pc.GetDayOfMonth(date);
return $"{year}{seprator}{month.ToString().PadLeft(2, '0')}{seprator}{day.ToString().PadLeft(2, '0')}";
}
}
}