How to convert normal date to solar date(PersianCalendar)

Mansour_Dalir 1,611 Reputation points
2024-04-30T04:04:17.3366667+00:00

with System.Globalization.PersianCalendar NameSpace

Need function to convert to solar date

VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,591 questions
0 comments No comments
{count} votes

Accepted answer
  1. Jiachen Li-MSFT 26,916 Reputation points Microsoft Vendor
    2024-04-30T07:34:05.98+00:00

    Hi @Mansour_Dalir ,

    The PersianCalendar Class document already provide the code that can convert Date or DateTime to a Persian Calendar datetime.

            Dim pc As New PersianCalendar()
            Dim thisDate As Date = Date.Now
    
            ' Display the current date using the Gregorian and Persian calendars. 
            Console.WriteLine("Today in the Gregorian Calendar:  {0:dddd}, {0}", thisDate)
            Console.WriteLine("Today in the Persian Calendar:    {0}, {1}/{2}/{3} {4}:{5}:{6}",  
                          pc.GetDayOfWeek(thisDate),
                          pc.GetMonth(thisDate),
                          pc.GetDayOfMonth(thisDate), 
                          pc.GetYear(thisDate),
                          pc.GetHour(thisDate),
                          pc.GetMinute(thisDate),
                          pc.GetSecond(thisDate))
            Console.WriteLine()
            
            ' Create a date using the Gregorian calendar.
            thisDate = New DateTime(2013, 5, 28, 10, 35, 0)
            Console.WriteLine("Gregorian Calendar:  {0:D} ", thisDate)
            Console.WriteLine("Persian Calendar:    {0}, {1}/{2}/{3} {4}:{5}:{6}", 
                          pc.GetDayOfWeek(thisDate),
                          pc.GetMonth(thisDate),
                          pc.GetDayOfMonth(thisDate), 
                          pc.GetYear(thisDate),
                          pc.GetHour(thisDate),
                          pc.GetMinute(thisDate),
                          pc.GetSecond(thisDate))
            Console.WriteLine()
    
    

    Best Regards.

    Jiachen Li


    If the answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful