;; 
;;=====================================================================================----- 
;; 
;;FUNCTION       DateUniversal() 
;; 
;;ACTION         Returns a ISO-Standard date/time string (YYYY/MM/DD HH/MM/SS) from local PC 
;; 
;;AUTHOR         Glenn Barnas 
;; 
;;VERSION        1.0  - 2018/06/20 
;; 
;;HISTORY        1.0  - 2018/06/20 - Original Release 
;; 
;;SYNTAX         DateUniversal([Mode]) 
;; 
;;PARAMETERS     Mode - OPTIONAL - Returns a string if non-zero, array otherwise 
;;                                 0 = Array of Local, UTC, and Timezone bias:name array 
;;                                 1 = Return the Local timestamp as a string 
;;                                 2 = Return the UTC timestamp as a string 
;; 
;;REMARKS        Use for internationalization of date processing 
;; 
;;RETURNS        Array of Local, UTC timestamps, TZ info or Timestamp string 
;; 
;;DEPENDENCIES   WMI 
;; 
;;TESTED WITH    W2K8, W2K12, W2K16 
;; 
;;EXAMPLES        
; 
Function DateUniversal(Optional $_Mode)
 
  Dim $_oWMIService, $_cItems, $_oItem				; WMI Object references 
  Dim $_aData[2]						; Data array 
 
  If $_Mode < 0 Or $_Mode > 2					; invalid mode specified 
    Exit 87
  EndIf
 
  $_oWMIService = GetObject('winmgmts:\\.\root\cimv2')
  If @ERROR Exit @ERROR EndIf
 
  $_cItems = $_oWMIService.ExecQuery('Select * from Win32_LocalTime',,48)
  If @ERROR Exit @ERROR EndIf
 
  For each $_oItem in $_cItems					; Date Time for Local, then UTC 
    $_aData[0] = '' + $_oItem.Year  + '/' + Right('00' + $_oItem.Month, 2) + '/' + Right('00' + $_oItem.Day, 2)
    $_aData[0] = $_aData[0] + ' ' + Right('00' + $_oItem.Hour, 2) + ':' + Right('00' + $_oItem.Minute, 2) + ':' + Right('00' + $_oItem.Second, 2)
  Next
 
  $_cItems = 0
  $_cItems = $_oWMIService.ExecQuery('Select * from Win32_UTCTime',,48)
  If @ERROR Exit @ERROR EndIf
 
  For each $_oItem in $_cItems					; Date Time for Local, then UTC 
    $_aData[1] = '' + $_oItem.Year  + '/' + Right('00' + $_oItem.Month, 2) + '/' + Right('00' + $_oItem.Day, 2)
    $_aData[1] = $_aData[1] + ' ' + Right('00' + $_oItem.Hour, 2) + ':' + Right('00' + $_oItem.Minute, 2) + ':' + Right('00' + $_oItem.Second, 2)
  Next
 
  $_cItems = 0
  $_cItems = $_oWMIService.ExecQuery('Select * from Win32_TimeZone',,48)
  If @ERROR Exit @ERROR EndIf
 
  For each $_oItem in $_cItems					; Timezone Data 
    $_aData[2] = $_oItem.Bias, $_oItem.Caption
  Next
 
  Select
   Case $_Mode = 1
    $DateUniversal = $_aData[0]
   Case $_Mode = 2
    $DateUniversal = $_aData[1]
   Case 1
    $DateUniversal = $_aData
  EndSelect
 
  Exit 0
 
EndFunction