|
| ||||||||||
| Tags: convert, datetime |
![]() |
| | Thread Tools | Search this Thread |
|
#1
| |||
| |||
| Convert datetime to small date in C#
Thanks |
|
#2
| |||
| |||
| Re: Convert datetime to small date in C#
You can Format time and date by using following code Code: using System;
class MainClass {
public static void Main() {
DateTime dt = DateTime.Now;
Console.WriteLine("Time is {0:hh:mm tt}", dt);
}
} |
|
#3
| |||
| |||
| Re: Convert datetime to small date in C#
To convert a string-based date to a System .DateTime object, you can use the Convert.ToDateTime(String) method or the DateTime.Parse static methodthod. Eg. Code: // Date strings are interpreted according to the current culture.
// If the culture is en-US, this is interpreted as "January 8, 2008",
// but if the user's computer is fr-FR, this is interpreted as "August 1, 2008"
string date = "01/08/2008";
DateTime dt = Convert.ToDateTime(date);
Console.WriteLine("Year: {0}, Month: {1}, Day: {2}", dt.Year, dt.Month, dt.Day);
// Specify exactly how to interpret the string.
IFormatProvider culture = new System.Globalization.CultureInfo("fr-FR", true);
// Alternate choice: If the string has been input by an end user, you might
// want to format it according to the current culture:
// IFormatProvider culture = System.Threading.Thread.CurrentThread.CurrentCulture;
DateTime dt2 = DateTime.Parse(date, culture, System.Globalization.DateTimeStyles.AssumeLocal);
Console.WriteLine("Year: {0}, Month: {1}, Day {2}", dt2.Year, dt2.Month, dt2.Day);
/* Output (assuming first culture is en-US and second is fr-FR):
Year: 2008, Month: 1, Day: 8
Year: 2008, Month: 8, Day 1
*/ |
|
#4
| |||
| |||
| Re: Convert datetime to small date in C#
Console.WriteLine("{0}/{1}/{2}", DateTime.Now.ToString("dd"), DateTime.Now.ToString("MM"), DateTime.Now.ToString("yy")) |
![]() |
|
| Thread Tools | Search this Thread |
| |
Similar Threads for: "Convert datetime to small date in C#" | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to convert Date and Time Formats in VB.Net | Jamaima | Software Development | 4 | 08-07-2010 06:20 PM |
| How to convert DateTime to Date and vice versa in c#? | Madaleno | Software Development | 4 | 05-03-2010 08:35 PM |
| How to convert string into DateTime | Segvoia | Software Development | 7 | 05-03-2010 01:55 PM |
| How to convert date format in postgres | Sayam | Software Development | 3 | 18-03-2009 11:08 PM |
| Convert Hex Value to Date from Binary Reg Key | RobT | Windows Server Help | 4 | 01-04-2005 10:55 AM |