Compartilhar via


Win32_CurrentTime class

The Win32_CurrentTime abstract is a singleton WMI class that describes a point in time by using the component items, such as milliseconds, seconds, minutes, hours, days, days of the week, week in the month, months, quarters, and years.

The following two important classes are derived from this class. Win32_LocalTime allows you to monitor time in local reference and Win32_UTCTime allows you to monitor time in coordinated universal time (UTC) reference.

The following syntax is simplified from Managed Object Format (MOF) code and includes all of the inherited properties. Properties are listed in alphabetic order, not MOF order.

Syntax

[Abstract, Singleton, AMENDMENT]
class Win32_CurrentTime
{
  uint32 Day;
  uint32 DayOfWeek;
  uint32 Hour;
  uint32 Milliseconds;
  uint32 Minute;
  uint32 Month;
  uint32 Quarter;
  uint32 Second;
  uint32 WeekInMonth;
  uint32 Year;
};

Members

The Win32_CurrentTime class has these types of members:

Properties

The Win32_CurrentTime class has these properties.

Day

Data type: uint32

Access type: Read-only

Current day that matches the query (1 31).

DayOfWeek

Data type: uint32

Access type: Read-only

Current day of the current week that match the query (0 6). By convention, the value 0 (zero) is always Sunday, regardless of the culture or the locale set on the machine.

Hour

Data type: uint32

Access type: Read-only

Current hour of the current day (0 23).

Milliseconds

Data type: uint32

Access type: Read-only

Not used.

This property is not returned.

Minute

Data type: uint32

Access type: Read-only

Current minute (0 59).

Month

Data type: uint32

Access type: Read-only

Current month that matches the query (1 12).

Quarter

Data type: uint32

Access type: Read-only

Current quarter of the current year (1 4).

Second

Data type: uint32

Access type: Read-only

Current second of the current minute (0 59).

WeekInMonth

Data type: uint32

Access type: Read-only

Current week (1 6) in the current month (1 12).

Year

Data type: uint32

Access type: Read-only

Current year that matches the query (4 digits).

Remarks

You cannot subscribe to events with this class because it is abstract and cannot have instances. However, use either Win32_LocalTime or Win32_UTCTime to subscribe to events.

Examples

The following PowerShell code sample displays both local and UTC time.

# Get Local Time and UTC Time
$Localtime, $UTCTime = gwmi win32_currenttime

# Display local and UTC time
"Local Time:"
" Day           : {0}" -f $localtime.day
" Day Of Week   : {0}" -f $localtime.dayofweek
" Hour          : {0}" -f $localtime.hour
" Milliseconds  : {0}" -f $localtime.Milliseconds
" Minute        : {0}" -f $localtime.minute
" Month         : {0}" -f $localtime.month
" Quarter       : {0}" -f $localtime.quarter
" Second        : {0}" -f $localtime.second
" Week in Month : {0}" -f $localtime.weekinmonth
" Year          : {0}" -f $localtime.year
""

# Display UTC
"UTC Time:"
" Day           : {0}" -f $UTCTime.day
" Day Of Week   : {0}" -f $UTCTime.dayofweek
" Hour          : {0}" -f $UTCTime.hour
" Milliseconds  : {0}" -f $UTCTime.Milliseconds
" Minute        : {0}" -f $UTCTime.minute
" Month         : {0}" -f $UTCTime.month
" Quarter       : {0}" -f $UTCTime.quarter
" Second        : {0}" -f $UTCTime.second
" Week in Month : {0}" -f $UTCTime.weekinmonth
" Year          : {0}" -f $UTCTime.year
""

The previous code sample creates the following output:

Local Time:
 Day           : 23
 Day Of Week   : 6
 Hour          : 14
 Milliseconds  :
 Minute        : 28
 Month         : 6
 Quarter       : 2
 Second        : 16
 Week in Month : 4
 Year          : 2007

UTC Time:
 Day           : 23
 Day Of Week   : 6
 Hour          : 13
 Milliseconds  :
 Minute        : 28
 Month         : 6
 Quarter       : 2
 Second        : 16
 Week in Month : 4
 Year          : 2007

Requirements

Minimum supported client
Windows Vista
Minimum supported server
Windows Server 2008
Namespace
Root\CIMV2
MOF
Wmitimep.mof
DLL
Wmitimep.dll

See also

Operating System Classes

Win32_LocalTime

Win32_UTCTime

Creating a Timer Event with Win32_LocalTime or Win32_UTCTime