C# DateTime Millisecond

Description

DateTime Millisecond gets the milliseconds component of the date represented by this instance.

Syntax

DateTime.Millisecond has the following syntax.


public int Millisecond { get; }

Example

Display the string representation of the Millisecond property by using the "fff" format specifier. For example, the following code displays a string that contains the number of milliseconds in a date and time to the console.


using System;/*from w  w  w.  ja va 2  s .c o  m*/
public class MainClass{
  public static void Main(String[] argv){  
    DateTime date1 = new DateTime(2008, 1, 1, 0, 30, 45, 125);
    System.Console.WriteLine("Milliseconds: {0:fff}", 
                      date1);           // displays Milliseconds: 125

  }
}   

The code above generates the following result.

Example 2

You can also display the millisecond component together with the other components of a date and time value by using the "o" standard format specifier. For example:


using System;// w w w. jav a 2  s .  c o m
public class MainClass{
  public static void Main(String[] argv){  
    DateTime date2 = new DateTime(2008, 1, 1, 0, 30, 45, 125);
    System.Console.WriteLine("Date: {0:o}", 
                      date2); 
  }
}

The code above generates the following result.

Example 3

You can also display milliseconds together with other date and time components by using a custom format string, as the following example shows.


using System;/*from  w w w.j a  va 2  s.c om*/
public class MainClass{
  public static void Main(String[] argv){  
    DateTime date3 = new DateTime(2008, 1, 1, 0, 30, 45, 125);
    Console.WriteLine("Date with milliseconds: {0:MM/dd/yyy hh:mm:ss.fff}", 
                      date3);

  }
}

The code above generates the following result.

Example 4

The following example demonstrates the Millisecond property.


using System;/*from ww  w. j  av  a2  s.  c  o m*/
public class MainClass{
  public static void Main(String[] argv){  
    System.DateTime moment = new System.DateTime(1999, 1, 13, 3, 57, 32, 11);
  int millisecond = moment.Millisecond;
  
    System.Console.WriteLine();
  }
}    




















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version