how to write coding for get date this format 03/04/2014 18:00:00 Hrs in c# code with example

Posted by Venky.Net under ASP.NET on 4/11/2014 | Points: 10 | Views : 774 | Status : [Member] | Replies : 2
hi
i want display date this format 03/04/2014 18:00:00 Hrs in c# code with example




Responses

Posted by: Vinothkumar on: 4/11/2014 [Member] Starter | Points: 25

Up
0
Down
string datetime= DateTime.Now.ToString("dd/mm/yyyy HH:mm:ss");

Regards,
Vinoth kumar

Venky.Net, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: A2h on: 4/11/2014 [Member] [MVP] Silver | Points: 25

Up
0
Down
Hi,

There are mutiple ways you can acheive this

First you need to convert your DateTime value to string and then you can use the available string formatting options for DateTime objects.
1) Using String.Format

Check the below code
    //Convert the value to your desired format
string formattedval = String.Format("{0:dd/mm/yyyy HH:mm:ss}", DateTime.Now);

Refer the below link for multiple formats
http://www.csharp-examples.net/string-format-datetime/

You can find a working sample demo in below link
http://dotnetfiddle.net/L2TuqP

Thanks,
A2H
My Blog

Venky.Net, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response