Introduction
You can use this library for creating PersianDateTime
as easy as using DateTime.
Actually, This library is a wrapper for DateTime
and PersianCalendar
.
This library can create and parse most of popular persian datetime strings.
The last version is on www.github.com/Mds92/MD.PersianDateTime
Background
I've seen before Mohammad Mir mostafa, PersianDateTime, It's great and you can use it too.
Using the code
Installing this library by nuget:
Install-Package MD.PersianDateTime
You can use it as the following:
static void Main(string[] args)
{
PersianDateTime persianDateTime = new PersianDateTime(DateTime.Now);
Console.WriteLine(persianDateTime);
Console.ReadKey();
}
Also, This Library can parse some persian datetime like the followings:
13930914
"1393/09/14 12:20:30"
"93/1/1 3:15 ب.ظ"
"1393/02/01 02:03:10:30"
"1393/09/14 12:20:30:300"
"1393/09/14 12:20 ب.ظ"
"1393/09/14"
"د 24 آذر 1393 4:2:5:5 ب.ظ"
"24 آذر 1393"
"جمعه 93/2/1 ساعت 3:2 ب.ظ"
"جمعه 14 آذر 1393 ساعت 11:50:30 ب.ظ"
"جمعه 14 آذر 1393 ساعت 16:50:30"
You can use this class directly instead of DateTime
static void Main(string[] args)
{
PersianDateTime persianDateTime = PersianDateTime.Parse("1393/09/15 12:20:30");
PrintDateTime(persianDateTime);
Console.ReadKey();
}
static void PrintDateTime(DateTime dateTime)
{
Console.WriteLine(dateTime);
}
You can change all numbers to Persian Numbers by setting EnglishNumber
property to false
(default is false)
Some outputs :
public override string ToString()
public string ToShortDateString()
public int ToShortDateInt()
public string ToShortDate1String()
public string ToLongDateString()
public string ToLongDateTimeString()
public string ToShortDateTimeString()
public string ToShortTimeString()
public string ToLongTimeString()
public string ToString(string format)
public string ElapsedTime()
public DateTime Date
History
First post: 6th December 2014
7th December 2014 : Updated source code
8th December 2014 : Updated source code
9th December 2014 : Updated source code ( Adding format )
17th December 2014 : Improved parser
19th December 2014 : fixed some bugs
21th December 2014 : added some methods
22th December 2014 : Updated source code
23th December 2014 : Updated source code
27th December 2014 : Updated source code
3th January 2015: Supporting arabic chars in parsing
12th January 2015: Added some useful properties
13th April 2015: Added Date property
17th May 2015: Coverted to struct and fixed some bugs
11th July 2015: GetStartDayOfRamadan method added and fixed some bugs
27th July 2015: fix a bug in `GetWeekOfMonth`
5th Septembar 2015: fixed some bugs