Click here to Skip to main content
12,831,625 members (33,181 online)
Click here to Skip to main content
Add your own
alternative version

Stats

18.3K views
492 downloads
6 bookmarked
Posted 14 May 2011

Get Full Shamsi Date in String Format with C# Class

, 2 Dec 2013 CPOL
Rate this:
Please Sign up or sign in to vote.
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.

 

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

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;
}
}
} 

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)

Figure 3

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

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:

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;
} 

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)

Share

About the Author

A. Najafzadeh
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/
==========================

You may also be interested in...

Comments and Discussions

 
GeneralMy vote of 1 Pin
Marco Bertschi1-Dec-13 9:27
professionalMarco Bertschi1-Dec-13 9:27 
GeneralMy vote of 1 Pin
ProgramFOX1-Dec-13 8:33
member ProgramFOX1-Dec-13 8:33 
GeneralMy vote of 1 Pin
Mahdi 821610215-May-12 20:44
memberMahdi 821610215-May-12 20:44 
GeneralMy vote of 1 Pin
V. Khachaturian10-Mar-12 2:08
memberV. Khachaturian10-Mar-12 2:08 
GeneralMy vote of 1 Pin
RusselSSC4-Mar-12 4:20
memberRusselSSC4-Mar-12 4:20 
SuggestionMy vote of 4 Pin
Shahin Khorshidnia6-Feb-12 6:49
memberShahin Khorshidnia6-Feb-12 6:49 
RantArrays Pin
Phorozan198016-May-11 19:16
memberPhorozan198016-May-11 19:16 
GeneralRe: Arrays Pin
Mr. Mox17-May-11 0:37
memberMr. Mox17-May-11 0:37 
GeneralRe: Arrays Pin
A. Najafzadeh20-Nov-11 23:24
memberA. Najafzadeh20-Nov-11 23:24 
GeneralRe: Arrays Pin
Shahin Khorshidnia4-May-12 11:28
memberShahin Khorshidnia4-May-12 11:28 
Generaljust a question Pin
Selvin16-May-11 3:07
memberSelvin16-May-11 3:07 
GeneralRe: just a question Pin
A. Najafzadeh18-May-11 6:20
memberA. Najafzadeh18-May-11 6:20 
GeneralMy vote of 2 Pin
Ali Aboutalebi15-May-11 2:21
memberAli Aboutalebi15-May-11 2:21 
Generalbuggy code Pin
Gilmore Radnor14-May-11 11:10
memberGilmore Radnor14-May-11 11:10 
GeneralRe: buggy code Pin
A. Najafzadeh18-May-11 6:21
memberA. Najafzadeh18-May-11 6:21 
GeneralRe: buggy code Pin
A. Najafzadeh23-May-14 9:59
memberA. Najafzadeh23-May-14 9: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.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170326.1 | Last Updated 2 Dec 2013
Article Copyright 2011 by A. Najafzadeh
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid