2

I have a textbox with this mask: year/ month /day hour :min

The datetime format is Persian like 1392/12/11 12:43

I need to convert this string to standard English format so I used pesiancalender class.

enter image description here

As you can see the function todate() expects the values separately, I don't know how can I separate the string to this values! I mean I don't know how can I detect year and month and day and hour and min in string.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Ehsan Akbar
  • 6,977
  • 19
  • 96
  • 180

1 Answers1

3

You can use either DateTime.TryParseExact method with providing the date format to it with culture info about persian date.


Edit: as I found out:

Currently, the PersianCalendar class is not an optional calendar for any culture supported by the CultureInfo class and consequently cannot be a default calendar.

So, you can't use the approach I've suggested. Some investigation led me to the this project for working with Persian date time and some hacks for the CultureInfo.

Such questions were already on SO, so I suggest to use their approach, and to write some helper class to solve your problem.

Community
  • 1
  • 1
VMAtm
  • 27,943
  • 17
  • 79
  • 125