Click here to Skip to main content
15,891,529 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
dDeleveryTimeAUS = new DateTime(Year, Month, Day, dHrs, dMins,dSec);

It displaying date format as "17/1/2012 12:00:00 PM"

but I need same dateformat as "AM"
Posted
Comments
Kaushik Saha from Kolkata,India 18-Jul-12 9:41am    
only AM means,DO YOU WANT HRS system

The "t" Custom Format Specifier
--------------------------------------------------------------------------------

The "t" custom format specifier represents the first character of the AM/PM designator. The appropriate localized designator is retrieved from the DateTimeFormatInfo.AMDesignator or DateTimeFormatInfo.PMDesignator property of the current or specific culture. The AM designator is used for all times from 0:00:00 (midnight) to 11:59:59.999. The PM designator is used for all times from 12:00:00 (noon) to 23:59:59.99.

If the "t" format specifier is used without other custom format specifiers, it is interpreted as the "t" standard date and time format specifier. For more information about using a single format specifier, see Using Single Custom Format Specifiers later in this topic.

The following example includes the "t" custom format specifier in a custom format string.


C#
DateTime date1; 
date1 = new DateTime(2008, 1, 1, 18, 9, 1);
Console.WriteLine(date1.ToString("h:m:s.F t", 
                  CultureInfo.InvariantCulture));
// Displays 6:9:1 P
Console.WriteLine(date1.ToString("h:m:s.F t", 
                  CultureInfo.CreateSpecificCulture("el-GR")));
// Displays 6:9:1 µ                        
date1 = new DateTime(2008, 1, 1, 18, 9, 1, 500);
Console.WriteLine(date1.ToString("h:m:s.F t", 
                  CultureInfo.InvariantCulture));
// Displays 6:9:1.5 P
Console.WriteLine(date1.ToString("h:m:s.F t", 
                  CultureInfo.CreateSpecificCulture("el-GR")));
// Displays 6:9:1.5 µ



Thanks,
Mamun
 
Share this answer
 
Comments
sandeep nagabhairava 18-Jul-12 14:10pm    
good job abdul...
C#
var dDeleveryTimeAUS = new DateTime(2012, 2, 1, 12, 0, 0).ToString(CultureInfo.GetCultureInfo("en-us")); 

will return 2/1/2012 12:00:00 PM

C#
var dDeleveryTimeAUS = new DateTime(2012, 2, 1, 0, 0, 0).ToString(CultureInfo.GetCultureInfo("en-us")); 

will return 2/1/2012 12:00:00 AM
 
Share this answer
 
v2
you can use

C#
Console.WriteLine(DateTime.Now.ToString("MM/dd/yyyy hh:mm tt"));

or
C#
DateTime date1 = new DateTime();
Console.WriteLine(date1.ToString("MM/dd/yyyy hh:mm tt"));
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900