C# .NET - How to convert the string date into the user defined format like ("MM:DD:YYYY hh:mm:ss"

Asked By umesh lohani
28-Jan-09 01:04 AM
end of post

See this  See this

28-Jan-09 01:09 AM
// Format the current time.
SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
Date currentTime_1 = new Date();
// Date for 13 Nov 2001
String dateString = "13/11/2001";

// Parse the string into a Date.
Date myDate = formatter.parse(dateString);

// If you want to format the Date -> String output...
SimpleDateFormat formatter2 = new SimpleDateFormat("EEE, d MMM yyyy");

String myDateString = formatter.format(myDate);
// Result is "Tue, 13 Nov 2001"

Refer this  Refer this

28-Jan-09 01:10 AM
Refer this table for date Format

Date Time Format with ToString()

All the patterns:
0    MM/dd/yyyy    09/10/2008
1    dddd, dd MMMM yyyy    Wednesday, 10 September 2008
2    dddd, dd MMMM yyyy HH:mm    Wednesday, 10 September 2008 04:35
3    dddd, dd MMMM yyyy hh:mm tt    Wednesday, 10 September 2008 04:35 AM
4    dddd, dd MMMM yyyy H:mm    Wednesday, 10 September 2008 4:35
5    dddd, dd MMMM yyyy h:mm tt    Wednesday, 10 September 2008 4:35 AM
6    dddd, dd MMMM yyyy HH:mm:ss    Wednesday, 10 September 2008 04:35:24
7    MM/dd/yyyy HH:mm    09/10/2008 04:35
8    MM/dd/yyyy hh:mm tt    09/10/2008 04:35 AM
9    MM/dd/yyyy H:mm    09/10/2008 4:35
10    MM/dd/yyyy h:mm tt    09/10/2008 4:35 AM
11    MM/dd/yyyy HH:mm:ss    09/10/2008 04:35:24
12    MMMM dd    September 10
13    MMMM dd    September 10
14    yyyy'-'MM'-'dd'T'HH':'mm':'ss.fffffffK    2008-09-10T04:35:24.1234802-04:00
15    yyyy'-'MM'-'dd'T'HH':'mm':'ss.fffffffK    2008-09-10T04:35:24.1234802-04:00
16    ddd, dd MMM yyyy HH':'mm':'ss 'GMT'    Wed, 10 Sep 2008 04:35:24 GMT
17    ddd, dd MMM yyyy HH':'mm':'ss 'GMT'    Wed, 10 Sep 2008 04:35:24 GMT
18    yyyy'-'MM'-'dd'T'HH':'mm':'ss    2008-09-10T04:35:24
19    HH:mm    04:35
20    hh:mm tt    04:35 AM
21    H:mm    4:35
22    h:mm tt    4:35 AM
23    HH:mm:ss    04:35:24
24    yyyy'-'MM'-'dd HH':'mm':'ss'Z'    2008-09-10 04:35:24Z
25    dddd, dd MMMM yyyy HH:mm:ss    Wednesday, 10 September 2008 04:35:24
26    yyyy MMMM    2008 September
27    yyyy MMMM    2008 September

The patterns for DateTime.ToString ( 'd' ) :
0    MM/dd/yyyy    09/10/2008

The patterns for DateTime.ToString ( 'D' ) :
0    dddd, dd MMMM yyyy    Wednesday, 10 September 2008

The patterns for DateTime.ToString ( 'f' ) :
0    dddd, dd MMMM yyyy HH:mm    Wednesday, 10 September 2008 04:35
1    dddd, dd MMMM yyyy hh:mm tt    Wednesday, 10 September 2008 04:35 AM
2    dddd, dd MMMM yyyy H:mm    Wednesday, 10 September 2008 4:35
3    dddd, dd MMMM yyyy h:mm tt    Wednesday, 10 September 2008 4:35 AM

The patterns for DateTime.ToString ( 'F' ) :
0    dddd, dd MMMM yyyy HH:mm:ss    Wednesday, 10 September 2008 04:35:24

The patterns for DateTime.ToString ( 'g' ) :
0    MM/dd/yyyy HH:mm    09/10/2008 04:35
1    MM/dd/yyyy hh:mm tt    09/10/2008 04:35 AM
2    MM/dd/yyyy H:mm    09/10/2008 4:35
3    MM/dd/yyyy h:mm tt    09/10/2008 4:35 AM

The patterns for DateTime.ToString ( 'G' ) :
0    MM/dd/yyyy HH:mm:ss    09/10/2008 04:35:24

The patterns for DateTime.ToString ( 'm' ) :
0    MMMM dd    September 10

The patterns for DateTime.ToString ( 'r' ) :
0    ddd, dd MMM yyyy HH':'mm':'ss 'GMT'    Wed, 10 Sep 2008 04:35:24 GMT

The patterns for DateTime.ToString ( 's' ) :
0    yyyy'-'MM'-'dd'T'HH':'mm':'ss    2008-09-10T04:35:24

The patterns for DateTime.ToString ( 'u' ) :
0    yyyy'-'MM'-'dd HH':'mm':'ss'Z'    2008-09-10 04:35:24Z

The patterns for DateTime.ToString ( 'U' ) :
0    dddd, dd MMMM yyyy HH:mm:ss    Wednesday, 10 September 2008 04:35:24

The patterns for DateTime.ToString ( 'y' ) :
0    yyyy MMMM    2008 September

Try this  Try this

28-Jan-09 01:16 AM
string RequiredFormat = DateTime.ToString ( 'G' ) // MM/dd/yyyy HH:mm:ss 
   RequiredFormat = RequiredFormat.Replace("//", ":"); // Replacing slahes with collon
Pop up window in asp.net c#  Pop up window in asp.net c#
27-Jul-09 08:33 AM

Hi,

Im working on a project in which i need to pop up a window when a certain condition matches.Say suppose i fix up an appointment at 2.30 pm for a caller.whn the time becomes 2.20 i wil pop up the window to alert the user that he has a cal at 2.30 pm.For working on this,im using a ajax timer and set the interval to be 6000.i wil cal a method inside the ajaxtimer_tick.i wil fill the datatable and check if the count is greater than 0.if it is greater than 0 i take the condition to be true and i want to pop up window showing the callername and the appointment time.When i use window.open im unable to use update panel in my page since every time the timer is triggered the page reloads.So is there any other option to do it?Its very urgent and i would be grateful if somebody can help me in doing this.

 

Bye.

 

 

Create New Account
help
Datetime format DateTime startTime; startTime = DateTime.Now; startTime contains value as 4:05 pm . . i want it as 16:05. . . . what to do String.Format("{0:d / M / yyyy HH:mm:ss}", dt) dateTime.Now. . ToString( "H:mm:ss" , CultureInfo.InvariantCulture)); You can look up all the DateTIme format specifiers in the MSDN documentation. there's no need for either String.Format call and CultureInfo.InvariantCulture. DateTime.Now.ToString("HH:mm"); will do just fine and return the time in format of: 09:32 or
DateTime here im getting the Time in _mytime. . _myTime = DateTime .Now.ToString( "HH:mm:ss" ).Replace( ":" , "_" ); but i need only the time in milliseconds thanks. . Try this to get MILLISECOND also; _myTime = DateTime .Now.ToString("HH:mm:ss.fff").Replace(":", "_") This will give you time like -> 12_08_08.328 If you instead of . then you can replace it as well same like you did for : hi, DateTime.Date This returns only the date component of the DateTime. It has the "time value set to 12:00:00 midnight
get date from datetime how to get only date part from a datetime object excluding time in sql server 2000 i want "11-25-2008" from "11-25 2008 10:30:15" See the following code using C = System . Console ; . . . static void Main ( ) { DateTime dateTime = DateTime . Now ; C. WriteLine ( "d = {0:d}" , dateTime ) ; / / mm / dd / yyyy C. WriteLine ( "D = {0:D}" , dateTime ) ; / / month dd, yyyy C. WriteLine ( "f
WepApp - DateTime.Now.Date.ToString() gives different results .NET Framework Hello, I'm facing a strange problem. We have an Asp.net 2.0 Web Application and somehow the date format is changing from one client to another even if all the code is running server-side. . . Here is the simple sample code used to reproduce the problem : DateTime date = DateTime.Now.Date; Response.Write("date.ToString() : " + date.ToString() + "<BR> "); Here is the result I get on my workstation : date.ToString
convert string to datetime i need to convert string to datetime in order by cluse in sql query in C#.net can you tell me the query i help me alot Hi, Find the below sample code - - SQL Server string to date / datetime conversion - datetime string format sql server - - MSSQL string to datetime conversion - convert char to date - convert varchar to date - - Subtract 100 from style number (format) for yy instead yyyy (or ccyy with century) SELECT