-2

im gettin the date in this format "3/16/2017 10:53:44 PM", how to get date in this format "16/3/2017 10:53:44 PM"

sample data

    "timestamp":"2017-03-16T17:23:44.860Z"


desired op
                "16/3/2017 10:53:44 PM"
    code
     binModel.UpdatedTime = TimeZoneInfo.ConvertTimeFromUtc(Convert.ToDateTime(bin.timestamp), TimeZoneInfo.FindSystemTimeZoneById("India Standard Time")).ToString();


    data type
      public String UpdatedTime { get; set; }
Swapna
  • 403
  • 3
  • 6
  • 24

4 Answers4

1

You need to convert it to string:

binModel.UpdatedTime = bin.timestamp.ToString("dd/MM/yyyy hh:mm:ss tt", CultureInfo.InvariantCulture));

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

Fady Wadie
  • 34
  • 4
1

Or Try to parse the datetime. For example

DateTime dateformat = DateTime.ParseExact(Convert.ToDateTime(bin.timestamp), "dd/M/yyyy h:mm:ss tt",CultureInfo.InvariantCulture);
binModel.UpdatedTime = TimeZoneInfo.ConvertTimeFromUtc(dateformat,TimeZoneInfo.FindSystemTimeZoneById("India Standard Time")).ToString();
Komal
  • 304
  • 1
  • 7
1

A DateTime has no display format.
Only string represnetations of DateTime does.
You can specify the desired format as a parameter in one of the the ToString method overloads of the DateTime struct:

 var s = DateTime.Now.ToString("dd/M/yyyy hh:mm:ss tt");

Now s contains the folowing string: "23/3/2017 09:01:32 AM" (my local time)

Zohar Peled
  • 79,642
  • 10
  • 69
  • 121
0
var currentDate = DateTime.Now.ToString("dd/MM/yyyy");
Gab David
  • 7
  • 4
  • Code-only answers are not considered as high quality answers. Please consider to put more context around your answer or put it as an comment. – ckruczek Mar 23 '17 at 07:56