-1

I have a dateTime stored in database using this line of code:

var now=DateTime.Now;

so after it stored, the data is like this in database and also after recalling the entity:

2019-01-26 17:27:46.297

when i try to convert it to another culture datetime using this method:

public static string ToPersianDate(this DateTime t)
    {
        var pc = new PersianCalendar();
       return $"{pc.GetYear(t)}/{pc.GetMonth(t)}/{pc.GetDayOfMonth(t)}";
    }

after using this method :

var persianDate=now.ToPersianDate();

I get this string as a result:

2019/01/26

But I expected to get this result:

1397/11/06

Z Daneshi
  • 57
  • 9

1 Answers1

-1

Here is a complete example that converts time to PersianCalender,

using System;
using System.Globalization;

namespace ConsoleApp1
{
    public class Program
    { 
        public static void Main(String[] args)
        {
            var date = DateTime.Now;
            var str = date.ToPersianDate();
            Console.WriteLine(str);
            Console.Read();
        }
    }

    public static class Extender
    {
        public static string ToPersianDate(this DateTime t)
        {
            var pc = new PersianCalendar();
            return $"{pc.GetYear(t)}/{pc.GetMonth(t)}/{pc.GetDayOfMonth(t)}";
        }
    }
}

your problem its not reproducible, code is attached for further reference

hessam hedieh
  • 780
  • 5
  • 18