Click here to Skip to main content
15,920,438 members
Articles / Programming Languages / C#

Get Full Shamsi Date in String Format with C# Class

Rate me:
Please Sign up or sign in to vote.
2.64/5 (11 votes)
2 Dec 2013CPOL 38.2K   619   6   16
Class used to display date in complete string format in Shamsi

Introduction

The requirement of programming projects is to display date in standard format. This paper has tried to use Visual Studio features for time display.

Image 1  

Figure 1 - This picture shows an example of how classes are used.

Requirements

You will need the following tools before using the class. These tools are needed for development:

  • Visual Studio .NET
  • .NET Framework  2.0 or higher

Using the Code

C#
public class ClassGetShamsiDay
{
private String DayName;
private String MonthName;
private String CompleteShamsiDate;

public ClassGetShamsiDay()
{
DateTime dt = DateTime.Now;
if (dt.DayOfWeek == DayOfWeek.Friday)
DayName = "جمعه";
if (dt.DayOfWeek == DayOfWeek.Saturday)
DayName = "شنبه";
if (dt.DayOfWeek == DayOfWeek.Sunday)
DayName = "یکشنبه";
if (dt.DayOfWeek == DayOfWeek.Monday)
DayName = "دوشنبه";
if (dt.DayOfWeek == DayOfWeek.Tuesday)
DayName = "سه شنبه";
if (dt.DayOfWeek == DayOfWeek.Wednesday)
DayName = "چهار شنبه";
if (dt.DayOfWeek == DayOfWeek.Thursday)
DayName = "پنج شنبه";

PersianCalendar pt = new PersianCalendar();
int MoName = pt.GetMonth(dt);

switch (MoName)
{
case 1:
MonthName = "فروردین";
break;
case 2:
MonthName = "اردیبهشت";
break;
case 3:
MonthName = "خرداد";
break;
case 4:
MonthName = "تیر";
break;
case 5:
MonthName = "مرداد";
break;
case 6:
MonthName = "شهریور";
break;
case 7:
MonthName = "مهر";
break;
case 8:
MonthName = "آبان";
break;
case 9:
MonthName = "آذر";
break;
case 10:
MonthName = "دی";
break;
case 11:
MonthName = "بهمن";
break;
case 12:
MonthName = "اسفند";
break;
}

CompleteShamsiDate = "امروز " + DayName + " " + pt.GetDayOfMonth(dt) + 
" " + MonthName + " " + pt.GetYear(dt) + " می باشد. ";
}

public String CRDaysName
{
set
{
DayName = value;
}
get
{
return DayName;
}
}

public String CRMotheName
{
set
{
MonthName = value;
}
get
{
return MonthName;
}
}

public String CRCompleteShamsiDate
{
set
{
CompleteShamsiDate = value;
}
get
{
return CompleteShamsiDate;
}
}
} 

Image 2

Figure 2

Using the DLL File

To use, the class should be added to the project. For this purpose, from the solution explorer, click on References. Then, click on the Add References... (as shown in Figure 2 above)

Image 3

Figure 3

Then a window opens. DLL File Choose and then click on OK (see Figure 3).

Image 4

Figure 4

After this step, the file has been added to the project (Figure 4).

How to Use

For using class, you need a form and button. On the Click Event, we program:

C#
private void button1_Click(object sender, EventArgs e)
{
     ShamsiDayLists.ClassGetShamsiDay shamsiDay = new ShamsiDayLists.ClassGetShamsiDay();
     label1.Text = shamsiDay.CRCompleteShamsiDate;
     label2.Text = shamsiDay.CRDaysName;
     label3.Text = shamsiDay.CRMotheName;
} 

Image 5

Figure 5

Conclusion

Now you can create as many forms and reports as you want and use the custom control to view complete Shamsi date in complete string mode. If you need help, do not hesitate to contact me.

License

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


Written By
Software Developer Bitasoft Co.
Iran (Islamic Republic of) Iran (Islamic Republic of)
Dear All
Thanks for read this words.

Bitasoft Co. was stablished in 2002. Our activity is programming.

We can supply you with best Source Codes and projects.

==========================
+989131253620
najafzade@gmail.com
http://www.a00b.com/
==========================

Comments and Discussions

 
GeneralMy vote of 1 Pin
Marco Bertschi1-Dec-13 8:27
protectorMarco Bertschi1-Dec-13 8:27 
GeneralMy vote of 1 Pin
Thomas Daniels1-Dec-13 7:33
mentorThomas Daniels1-Dec-13 7:33 
GeneralMy vote of 1 Pin
Mahdi 821610215-May-12 19:44
Mahdi 821610215-May-12 19:44 
GeneralMy vote of 1 Pin
Vartan Khachatourian10-Mar-12 1:08
Vartan Khachatourian10-Mar-12 1:08 
GeneralMy vote of 1 Pin
RusselSSC4-Mar-12 3:20
RusselSSC4-Mar-12 3:20 
1. It's a Tip not an article (-1)
2. Bad code. It does't need Switch/Case. Use array. (-1)
3. You don't improve your writing. It seems other people have reminded it but you are going to stay on this bad code (-1)
4. You've chosen a very repetitive subject. (-1)
5 - 1 - 1 - 1 - 1 = 1
That's why I downvoted this.
SuggestionMy vote of 4 Pin
Shahin Khorshidnia6-Feb-12 5:49
professionalShahin Khorshidnia6-Feb-12 5:49 
RantArrays Pin
Phorozan198016-May-11 18:16
Phorozan198016-May-11 18:16 
GeneralRe: Arrays Pin
Gustav Brock16-May-11 23:37
professionalGustav Brock16-May-11 23:37 
GeneralRe: Arrays Pin
A. Najafzadeh20-Nov-11 22:24
A. Najafzadeh20-Nov-11 22:24 
GeneralRe: Arrays Pin
Shahin Khorshidnia4-May-12 10:28
professionalShahin Khorshidnia4-May-12 10:28 
Generaljust a question Pin
Selvin16-May-11 2:07
Selvin16-May-11 2:07 
GeneralRe: just a question Pin
A. Najafzadeh18-May-11 5:20
A. Najafzadeh18-May-11 5:20 
GeneralMy vote of 2 Pin
Ali Aboutalebi15-May-11 1:21
Ali Aboutalebi15-May-11 1:21 
Generalbuggy code Pin
Gilmore Radnor14-May-11 10:10
Gilmore Radnor14-May-11 10:10 
GeneralRe: buggy code Pin
A. Najafzadeh18-May-11 5:21
A. Najafzadeh18-May-11 5:21 
GeneralRe: buggy code Pin
A. Najafzadeh23-May-14 8:59
A. Najafzadeh23-May-14 8:59 

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

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.