-4

i have a date in string format "Thu, 07 Jan 2016 07:00 PST" in c#.net console app.I want to convert it to dd/mm/yyyy format.Can anyone show me the code to do this?

  • These would help you to do it, https://msdn.microsoft.com/en-us/library/w2sa9yss(v=vs.110).aspx and https://msdn.microsoft.com/en-us/library/8kb3ddd4(v=vs.110).aspx – Adil Mar 17 '17 at 09:52
  • 7
    Possible duplicate of [Parsing string "Sat, 14 Jan 2017 12:12:12 Europe/Warsaw" to DateTime](http://stackoverflow.com/questions/41633727/parsing-string-sat-14-jan-2017-121212-europe-warsaw-to-datetime) – mrogal.ski Mar 17 '17 at 09:56
  • Possible duplicate of http://stackoverflow.com/questions/42811442/converting-datetime-string-in-ddd-mmm-dd-hhmmss-est-yyyy-format/42812411#42812411 Note that there is no "correct" parsing in .NET of timezone abbreviations (PST) – xanatos Mar 17 '17 at 10:01
  • And of http://stackoverflow.com/questions/241789/parse-datetime-with-time-zone-of-form-pst-cest-utc-etc – xanatos Mar 17 '17 at 10:02
  • You have to remove the `PST`part,and then it's easy to parse the string with `ParseExact` and `"ddd, dd MMM yyyy HH:mm"` – Pikoh Mar 17 '17 at 10:06
  • i have the string like this: String dateStr = "Thu, 07 Jan 2016 07:00 PST" ;I want a date time in dd/mm/yyyy format – Vishnu Mohan Mar 17 '17 at 10:10
  • @VishnuMohan that's completly different from the date string in your question. Make yourself clear – Pikoh Mar 17 '17 at 10:11
  • it's by mistake..i have editted my previous comment – Vishnu Mohan Mar 17 '17 at 10:14

2 Answers2

-1

How about converting it into a char array and then using that to reconstruct your string. for example:

  string str = "Thu, 07 Jan 2016 07:00 PST"
  var Chrarry = str.ToCharArray();
  //use a switch statament to find out that numerical value your month has for example jan = 01
  string newstr = chrarray[5] + chrarray[6] + "/"....
Valhalla
  • 1
  • 3
-1

You can change the format of DateTime. Try (dd/MM/yyyy)

Sample code:

DateTime now1 = DateTime.Now(); var now = now.ToString("dd/MM/yyy");

https://msdn.microsoft.com/en-us/library/8kb3ddd4(v=vs.110).aspx

Keshav
  • 93
  • 1
  • 1
  • 10