fork download
  1. using System;
  2. using static System.Console;
  3. using System.Globalization;
  4.  
  5. public class Program {
  6. public static void Main() {
  7. var data = "9/14/2016 12:00:00 AM";
  8. var date = DateTime.Parse(data, new CultureInfo("en-US")); //pega a data no formato
  9. WriteLine(date.ToString("dd/MM/yyyy", new CultureInfo("pt-BR"))); //imprime no formato desejado
  10. DateTime date2; //variável que receberá o valor se a conversão for ok
  11. if (DateTime.TryParseExact(data, "M/d/yyyy hh:mm:ss tt", CultureInfo.InvariantCulture, DateTimeStyles.None, out date2)) {
  12. WriteLine(date2.ToString("dd/MM/yyyy", new CultureInfo("pt-BR"))); //imprime no formato desejado
  13. }
  14. }
  15. }
  16.  
  17. //https://pt.stackoverflow.com/q/152781/101
Success #stdin #stdout 0.03s 17724KB
stdin
Standard input is empty
stdout
14/09/2016
14/09/2016