Click here to Skip to main content
Click here to Skip to main content

Persian Calendar with Simulated PHP Methods in C#

By , 1 Jan 2009
 
MDCalendar.jpg

Introduction

I was already using PHP for programming; I was using the following methods for date:

  • time
  • mktime
  • date

Since I'm using C#, I always like to write a class with these methods because usage of these methods is much easier than C# classes (in my opinion). Finally, I wrote this class and you can use it. You can use this library like PHP methods (time, mktime, date).

MohammadDayyanCalendar Methods

  • public uint Time()

    Returns the current time measured in the number of seconds since the Unix Epoch (January 1 1970 00:00:00 GMT).

  • public string Date(string Format, double Seconds, bool persianNumbers)
  • Returns a string formatted according to the given format string using the given double second. You can see all supported formats in the Persian document.

  • public int Mktime(int year, int month, int day, int hour, int minute, int second)

    Returns the Unix timestamp corresponding to the arguments given. This time is an integer containing the number of seconds between the Unix Epoch (January 1 1970 00:00:00 GMT) and the time specified.

Using the Code

Let's see how we can work with this class.

Add this class to your project references:

help01.jpg

help02.jpg

Now we can use this DLL in our own project:

public Form1()
{
    InitializeComponent();

    MDCalendar mdCalendar = new MDCalendar();
    DateTime date = DateTime.Now;
    TimeZone time = TimeZone.CurrentTimeZone;
    TimeSpan difference = time.GetUtcOffset(date);
    uint currentTime = mdCalendar.Time() + (uint)difference.TotalSeconds;
    label1.Text = mdCalendar.Date("W D M Y G   ....   d E Z A", currentTime, true);
    label2.Text = mdCalendar.Date("H : i : s", currentTime, true);
}

Enjoy!

History

  • 14th June, 2008: First post
  • 27th December, 2008: Last update

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Mohammad Dayyan
Iran (Islamic Republic Of) Iran (Islamic Republic Of)
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
Generalpublic uint Time() :memberXaroth15 Jun '08 - 1:13 
why not make it a signed int to make it uniform to mktime, solving the constant need of casting from uint to int when used together.
 
also, making it an uint assumes that there is nothing prior to 1-1-1970, while there is...
GeneralRe: public uint Time() :memberMohammad Dayyan15 Jun '08 - 3:33 
Thanks Xaroth for your notice.
I selected uint because the seconds between now and 1-1-1970 are always positive.
GeneralRe: public uint Time() :memberRob Graham1 Jan '09 - 13:07 
Mohammad Dayyan wrote:
I selected uint because the seconds between now and 1-1-1970 are always positiv

 
That statement makes absolutely no sense, and ignores the OP's complaint that making it a uint PREVENTS its use for times before the unix epoch, as well as not CLSCompliant.

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web01 | 2.6.130523.1 | Last Updated 1 Jan 2009
Article Copyright 2008 by Mohammad Dayyan
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid