Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8827353
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T07:21:05+00:00 2026-06-14T07:21:05+00:00

I use the function below to convert Gregorian dates to Persian dates, but I’ve

  • 0

I use the function below to convert Gregorian dates to Persian dates, but I’ve been unable to write a function to do the reverse conversion. I want a function that converts a Persian date (a string like “1390/07/18 12:00:00”) into a Georgian date.

public static string GetPdate(DateTime _EnDate)
{
    PersianCalendar pcalendar = new PersianCalendar();
    string Pdate = pcalendar.GetYear(_EnDate).ToString("0000") + "/" +
       pcalendar.GetMonth(_EnDate).ToString("00") + "/" +
       pcalendar.GetDayOfMonth(_EnDate).ToString("00") + " " +
           pcalendar.GetHour(_EnDate).ToString("00") + ":" +
           pcalendar.GetMinute(_EnDate).ToString("00") + ":" +
           pcalendar.GetSecond(_EnDate).ToString("00");

    return Pdate;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T07:21:06+00:00Added an answer on June 14, 2026 at 7:21 am

    DateTime is always in the Gregorian calendar, effectively. Even if you create an instance specifying a dfferent calendar, the values returned by the Day, Month, Year etc properties are in the Gregorian calendar.

    As an example, take the start of the Islamic calendar:

    using System;
    using System.Globalization;
    
    class Test
    {
        static void Main()
        {
            DateTime epoch = new DateTime(1, 1, 1, new HijriCalendar());
            Console.WriteLine(epoch.Year);  // 622
            Console.WriteLine(epoch.Month); // 7
            Console.WriteLine(epoch.Day);   // 18
        }
    }
    

    It’s not clear how you’re creating the input to this method, or whether you should really be converting it to a string format. (Or why you’re not using the built-in string formatters.)

    It could be that you can just use:

    public static string FormatDateTimeAsGregorian(DateTime input)
    {
        return input.ToString("yyyy'/'MM'/'dd' 'HH':'mm':'ss",
                              CultureInfo.InvariantCulture);
    }
    

    That will work for any DateTime which has been created appropriately – but we don’t know what you’ve done before this.

    Sample:

    using System;
    using System.Globalization;
    
    class Test
    {
        static void Main()
        {
            DateTime epoch = new DateTime(1, 1, 1, new PersianCalendar());
            // Prints 0622/03/21 00:00:00
            Console.WriteLine(FormatDateTimeAsGregorian(epoch));
        }
    
        public static string FormatDateTimeAsGregorian(DateTime input)
        {
            return input.ToString("yyyy'/'MM'/'dd' 'HH':'mm':'ss",
                                  CultureInfo.InvariantCulture);
        }
    }
    

    Now if you’re not specifying the calendar when you create the DateTime, then you’re not really creating a Persian date at all.

    If you want dates that keep track of their calendar system, you can use my Noda Time project, which now supports the Persian calendar:

    // In Noda Time 2.0 you'd just use CalendarSystem.Persian
    var persianDate = new LocalDate(1390, 7, 18, CalendarSystem.GetPersianCalendar());
    var gregorianDate = persianDate.WithCalendar(CalendarSystem.Iso);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I use htmlspecialchars function in my string. But, I don't want to clean them;
I usually use the SQL function below to convert bigint in sql to datetime
I want to convert function object to function. I wrote this code, but it
I use the code below to get records from two tables but I want
I use function below to check connection to WiFi hotspot point: public boolean IsWiFiConnected(){
I'm trying to use the function below to get a DIV to slide-out from
When I use jQuery event listener to handle message event, like below: $(window).on('message', function(e)
Unless I use the .toLocaleDateString() method, the function below returns a date that is
Based on this code below I use for regular mysql, how could I convert
I want to use a c# function which modifies a string for html valid

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.