KCalendar 1.1.0.1
dotnet add package KCalendar --version 1.1.0.1
NuGet\Install-Package KCalendar -Version 1.1.0.1
<PackageReference Include="KCalendar" Version="1.1.0.1" />
paket add KCalendar --version 1.1.0.1
#r "nuget: KCalendar, 1.1.0.1"
// Install KCalendar as a Cake Addin #addin nuget:?package=KCalendar&version=1.1.0.1 // Install KCalendar as a Cake Tool #tool nuget:?package=KCalendar&version=1.1.0.1
JCalendar
This is a plugin for converting Gregorian date and Persian date (Jalali) and Hijri (Islamic) date into each other.
Installation
Install the dependencies and devDependencies and start the server.
Install-Package KCalendar
Getting Started
**Persian Date (Jalali Date) **
For Create a Persian Date with specified year, month, day use the constructor :
PersianDate persianDate = new PersianDate(1396, 9, 23);
Or for create a Persian date with Date
:
PersianDate persianDate = new PersianDate(new Date());
in above code, will create new instance from DateTime.Now()
and get now date.
For create a Persian date with JulianDay :
PersianDate persianDate = new PersianDate(2458101.5);
Islamic Date (Hijri Date)
You can create instance of IslamicDate
similar to above example :
For Create a IslamicDate
with specified year, month, day use the constructor :
IslamicDate islamicDate= new IslamicDate(1396, 9, 23);
Or for create a IslamicDate with DateTime
:
IslamicDate islamicDate = new IslamicDate (DateTime.Now());
For create a IslamicDate with JulianDay :
IslamicDate islamicDate = new IslamicDate (2458101.5);
Gregorian Date
For Gregorian Date also similar to above example.
Convert date to together
For Convert Date to other just pass to new date constructor : Islamic to Persian date:
IslamicDate islamicDate ;/* = your constructor */
PersianDate persianDate =new PersianDate(islamicDate);
**Gregorian to Persian date 😗*
GregorianDate date; /* your constructor */
PersinaDate persianDate =new PersianDate(date);
and ...
You can also use the following method
IslamicDate islamicDate ;/* = your constructor */
PersianDate persianDate= (PersianDate)islamicDate.castTo(new PersianDate());
***** For the rest, you can look like the example above
Tip
There are two types of algorithms available for Persian history: one of the official Iranian algorithms and Ahmad Barashk's algorithm.
The PersianDate
class is official date that used in Iran and PersianArithmeticDate
class developed by Bireshks Algorithm .
You can use PersianArithmeticDate
like PersianDate
create instance way.
more information
Parse Date From Pattern
You can create new instance of PersianDate
with DateTimeFormatter
:
DateTimeFormatter fmt = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss");
date = fmt.parseDateTime(group.getTitle());
GregorianDate gregorianDate = new GregorianDate(date.getYear(),date.getMonthOfYear(), date.dayOfMonth().get());
ICalendar persianDate = gregorianDate.castTo(PersianDate.class);
Or using other methods written for this purpose.
parseFromPattern
toString Method :
Way 1 :
persian date
persianDate.toString(DateFormat.FullDate);// پنجشنبه 23 آذر 1396
persianDate.toString(DateFormat.LongDate); // پنجشنبه 23 آذر
persianDate.toString(DateFormat.Date);// 1396/09/23
persianDate.toString(DateFormat.ShortDate);// 09/23
Islamic date
islamicDate.toString(DateFormat.FullDate);//الخمیس‬ ٢٥ ربيع الاول ١٤٣٩
islamicDate.toString(DateFormat.LongDate); // الخميس ٢٥ ربيع الاول
islamicDate.toString(DateFormat.Date);// Û±Û´Û³Û¹/Û°Û³/Û²Ûµ
islamicDate.toString(DateFormat.ShortDate);// Û°Û³/Û²Ûµ
Or custom Pattern
d Represents the day of the month as a number from 1 through 31. A single-digit day is formatted without a leading zero
dd Represents the day of the month as a number from 01 through 31. A single-digit day is formatted with a leading zero
ddd Represents the abbreviated name of the day of the week (Mon, Tues, Wed etc)
dddd Represents the full name of the day of the week (Monday, Tuesday etc)
h 12-hour clock hour (e.g. 7)
hh 12-hour clock, with a leading 0 (e.g. 07)
H 24-hour clock hour (e.g. 19)
HH 24-hour clock hour, with a leading 0 (e.g. 19)
m Minutes
mm Minutes with a leading zero
M Month number
MM Month number with leading zero
MMM Abbreviated Month Name (e.g. Dec)
MMMM Full month name (e.g. December)
s Seconds
ss Seconds with leading zero
t Abbreviated AM / PM (e.g. A or P)
y Year, no leading zero (e.g. 2001 would be 1)
yy Year, leadin zero (e.g. 2001 would be 01)
yyy Year, (e.g. 2001 would be 2001)
yyyy Year, (e.g. 2001 would be 2001)
f Represents the most significant digit of the seconds fraction; that is, it represents the tenths of a second in a date and time value.
ff Represents the two most significant digits of the seconds fraction; that is, it represents the hundredths of a second in a date and time value.
fff Represents the three most significant digits of the seconds fraction; that is, it represents the milliseconds in a date and time value.
For example :
persianDate.toString("yyyy/MM/dd");// 1396/09/23
Custom Leap Algorithm
You can write for each type of your own Leap Algorithm
and use that algorithm, and you can also write for each one a specific Culture
.
For example:
public class PersianBirashkLeap implements ICalendarLeap {
public boolean isLeap(ICalendar date) {
return ((((((date.getYear() - ((date.getYear() > 0) ? 474 : 473)) % 2820) + 474) + 38) * 682) % 2816) < 682;
}
}
Above class is custom Leap Algorithm and now set leap Algorithm to Persian Date :
persianDate.setLeapAlgorithm(new PersianBirashkLeap());
More Detail About Persian Date
This article is taken from https://www.fourmilab.ch/ :
Acknowledgment
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET Framework | net45 is compatible. net451 was computed. net452 was computed. net46 was computed. net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
This package has no dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Convert Date to other calendar date.