Date time Value from DateTimeOffset
In this chapter you will learn:
Gets hour from DateTimeOffset
using System;//from j a v a 2s . c o m
using System.Globalization;
public class Test
{
public static void Main()
{
DateTimeOffset theTime = new DateTimeOffset(2008, 3, 1, 14, 15, 00, DateTimeOffset.Now.Offset);
Console.WriteLine("The hour component of {0} is {1}.", theTime, theTime.Hour);
Console.WriteLine("The hour component of {0} is{1}.", theTime, theTime.ToString(" H"));
Console.WriteLine("The hour component of {0} is {1}.",theTime, theTime.ToString("HH"));
Console.WriteLine("The second component of {0} is {1}.", theTime, theTime.Second);
}
}
Gets year from DateTimeOffset
using System;//from j ava 2 s. co m
using System.Globalization;
public class Example
{
public static void Main()
{
DateTimeOffset theTime = new DateTimeOffset(2008, 2, 17, 9, 0, 0, DateTimeOffset.Now.Offset);
Console.WriteLine("The year component of {0} is {1}.", theTime, theTime.Year);
}
}
Next chapter...
What you will learn in the next chapter:
- Use the Compare() method to compare DateTime instances
- Use the overloaded less than operator (<) to compare two DateTime instances
- Use the Equals() method to compare DateTime instances
Home » C# Tutorial » Date, Time, TimeZone