List the UTC Time on a Computer

该博客介绍了一个可报告计算机通用协调时间(UTC)的Python脚本,此脚本在Microsoft Windows系统上测试,版本为Python 2.2.2 - 224。同时给出了在线支持社区及反馈途径,还对脚本免责声明进行说明。

Description

Reports the Universal Time Coordinate (UTC) time on a computer.

This script was tested using Python 2.2.2-224 for Microsoft Windows, available from ActiveState.

Supported Platforms

Windows Server 2003

Yes

Windows XP

Yes

Windows 2000

No

Windows NT 4.0

No

Windows 98

No

Script Code

import win32com.client
strComputer = "."
objWMIService = win32com.client.Dispatch("WbemScripting.SWbemLocator")
objSWbemServices = objWMIService.ConnectServer(strComputer,"root\cimv2")
colItems = objSWbemServices.ExecQuery("Select * from Win32_UTCTime")
for objItem in colItems:
    print "Day: ", objItem.Day
    print "Day Of Week: ", objItem.DayOfWeek
    print "Hour: ", objItem.Hour
    print "Milliseconds: ", objItem.Milliseconds
    print "Minute: ", objItem.Minute
    print "Month: ", objItem.Month
    print "Quarter: ", objItem.Quarter
    print "Second: ", objItem.Second
    print "Week In Month: ", objItem.WeekInMonth
    print "Year: ", objItem.Year

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

The sample scripts are not supported under any Microsoft standard support program or service. The sample scripts are provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.

USE [DXQcontrol_VWAnhuiCP2PS01_Operational_W] GO /****** Object: StoredProcedure [dbo].[DS_SP_AlsAlarmsInsert] Script Date: 7/25/2025 9:45:04 AM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- 2005-08-22, SDR: Stores a new alarm in database -- 2006-02-28, JM: read the priority from the DS_AlsTags_TAB, if possible -- 2024-01-30, LZ: extend argument @arg_dynItemId from 11 to 17 digits -- internal component message number extend from 4 to 10 digits ALTER PROCEDURE [dbo].[DS_SP_AlsAlarmsInsert] @arg_utc_dts_new_on DATETIME, @arg_computer NVARCHAR(16), @arg_ionode NVARCHAR(32), @arg_ioitem NVARCHAR(64), @arg_text_id NVARCHAR(32), @arg_priority INT, @arg_localTimeDiff INT, -- offset in seconds from UTC to local time -- the following parameters are only valid for dynamic messages; -- for dynamic messages the meaning of "@arg_dynItemId" is the same -- like "@arg_ioitem" in case of static messages; -- all of these parameters are an empty string ('') for static messages @arg_dynItemId NVARCHAR(17), -- 17 character which includes: -- 1..4 : component -- 5..7 : device identifier -- 8..17 : internal component message number @arg_deviceId NVARCHAR(3), -- character 5..7 of @arg_dynItemId @arg_message NVARCHAR(128) AS BEGIN SET NOCOUNT ON; -- constants DECLARE @procName NVARCHAR(128) = OBJECT_SCHEMA_NAME(@@PROCID) + '.' + OBJECT_NAME(@@PROCID); DECLARE @lengthDynItemId TINYINT = 17; -- length of parameter @arg_dynItemId; use the variable instead of fix length inside the code -- variables DECLARE @iError INT; DECLARE @iRowCount INT; DECLARE @szErrType NVARCHAR(32); DECLARE @szErrMsg NVARCHAR(MAX); DECLARE @bDynAlarm TINYINT; DECLARE @bDynTagBreak TINYINT; DECLARE @szDynTextId NVARCHAR(32); DECLARE @szDynLamEnglish NVARCHAR(128); DECLARE @szDynToken NVARCHAR(128); DECLARE @bDynParamIndex TINYINT; DECLARE @sDynStartPos SMALLINT; DECLARE @sDynEndPos SMALLINT; DECLARE @ioitem NVARCHAR(64); DECLARE @cfg_inst_structure BIGINT; DECLARE @areakey NVARCHAR(96); DECLARE @plant_type CHAR(1); DECLARE @class CHAR(2); DECLARE @shiftnr TINYINT; DECLARE @wtmid INT; DECLARE @iAlsTagsPriority INT; DECLARE @local_dts_new_on DATETIME; DECLARE @tTypIdOfShift TINYINT; DECLARE @szSyncAlarms NVARCHAR(8); ------------------------------------------------------------------------------- -- Check the input parameters IF (@arg_utc_dts_new_on IS NULL OR @arg_computer IS NULL OR @arg_ionode IS NULL OR @arg_ioitem IS NULL OR @arg_priority IS NULL OR @arg_localTimeDiff IS NULL) BEGIN EXEC [dbo].[DS_SP_WriteToDSErrorLog] @procName, N'ERROR', N'Invalid parameters'; RETURN 0; END; IF (LEN(@arg_computer) = 0 OR LEN(@arg_ionode) = 0 OR LEN(@arg_ioitem) = 0) BEGIN EXEC [dbo].[DS_SP_WriteToDSErrorLog] @procName, N'ERROR', N'Invalid parameters'; RETURN 0; END; SET @szErrType = N'WARNING'; SET @szErrMsg = N''; SET @cfg_inst_structure = NULL; ------------------------------------------------------------------------------- -- check whether this is a dynamic alarm SET @bDynAlarm = 0; SET @ioitem = @arg_ioitem; IF (@arg_dynItemId IS NOT NULL AND @arg_deviceId IS NOT NULL) BEGIN IF (LEN(@arg_dynItemId) > 0 AND LEN(@arg_deviceId) > 0) BEGIN SET @bDynAlarm = 1; SET @ioitem = @arg_dynItemId; END; END; -- if (@arg_dynItemId is not null and @arg_deviceId is not null) IF (@bDynAlarm = 0) BEGIN SELECT TOP(1) @cfg_inst_structure = [cfg_inst_structure], @areakey = [areakey], @plant_type = [plant_type], @iAlsTagsPriority = [priority], @class = [class] FROM [dbo].[DS_AlsTags_TAB] WHERE ([ionode] = @arg_ionode AND [ioitem] = @ioitem) ORDER BY [id] DESC; SELECT @iError = @@ERROR, @iRowCount = @@ROWCOUNT; END; ELSE BEGIN BEGIN TRANSACTION; SET @iRowCount = 0; SELECT TOP(1) @cfg_inst_structure = ISNULL([DYN].[cfg_inst_structure], [DATT].[cfg_inst_structure]), @areakey = ISNULL([DYN].[areakey],[DATT].[areakey]), @plant_type = ISNULL([DYN].[plant_type],[DATT].[plant_type]), @iAlsTagsPriority = ISNULL([DYN].[priority],[DATT].[priority]), @class = ISNULL([DYN].[class],[DATT].[class]), @iRowCount = (CASE WHEN [DYN].[ionode] IS NULL THEN 0 ELSE 1 END) FROM [dbo].[DS_AlsTags_TAB] [DATT] WITH (ROWLOCK XLOCK) RIGHT JOIN [dbo].[DS_AlsDynTags_TAB] [DYN] WITH (ROWLOCK XLOCK) ON [DYN].[ionode] = [DATT].[ionode] AND [DYN].[ioitem] = [DATT].[ioitem] WHERE ([DYN].[ionode] = @arg_ionode AND [DYN].[ioitem] = @ioitem) ORDER BY [DYN].[id] DESC; IF @iRowCount = 0 BEGIN -- in case of dynamic tags the arg_priority is used INSERT INTO [dbo].[DS_AlsDynTags_TAB] ([ionode], [ioitem], [plant_id], [plant_type], [equipment_id], [devicename], [groupkey], [cfg_inst_structure], [text_id], [class], [location], [active], [priority], [log_enabled], [areakey]) SELECT @arg_ionode, @ioitem, [plant_id], [plant_type], [equipment_id], @arg_deviceId, [groupkey], [cfg_inst_structure], @arg_text_id, [class], [location], [active], @arg_priority, [log_enabled], [areakey] FROM [dbo].[DS_AlsTags_TAB] WHERE ([ionode] = @arg_ionode AND [ioitem] = @arg_ioitem); SELECT @iError = @@ERROR, @iRowCount = @@ROWCOUNT; SELECT TOP(1) @cfg_inst_structure = ISNULL([DYN].[cfg_inst_structure], [DATT].[cfg_inst_structure]), @areakey = ISNULL([DYN].[areakey],[DATT].[areakey]), @plant_type = ISNULL([DYN].[plant_type],[DATT].[plant_type]), @iAlsTagsPriority = ISNULL([DYN].[priority],[DATT].[priority]), @class = ISNULL([DYN].[class],[DATT].[class]), @iRowCount = (CASE WHEN [DYN].[ionode] IS NULL THEN 0 ELSE 1 END) FROM [dbo].[DS_AlsTags_TAB] [DATT] WITH (ROWLOCK XLOCK) RIGHT JOIN [dbo].[DS_AlsDynTags_TAB] [DYN] WITH (ROWLOCK XLOCK) ON [DYN].[ionode] = [DATT].[ionode] AND [DYN].[ioitem] = [DATT].[ioitem] WHERE ([DYN].[ionode] = @arg_ionode AND [DYN].[ioitem] = @ioitem) ORDER BY [DYN].[id] DESC; END; -- IF @iRowCount = 0 COMMIT TRANSACTION; END; -- else of 'if (@bDynAlarm = 0)' IF (@iError <> 0 OR @iRowCount <> 1) BEGIN SET @szErrMsg = N'AlarmTag does not exist for node '+ @arg_ionode + N' and item ' + @ioitem + N';error=' + CAST(@iError AS NVARCHAR(16)) + N';row count=' + CAST(@iRowCount AS NVARCHAR(16)); GOTO afterTransaction; END; ------------------------------------------------------------------------------- -- If this is a 'dynamic' or a 'dynamic direct' alarm then store -- the message text direct in the attribute 'message' of the new alarm -- Note: because of that direct storage only one language is supported -- in the attribute 'message' (the default language is 'en') SET @szDynLamEnglish = N''; IF (LEN(ISNULL(@arg_message,N'')) > 0) BEGIN IF (@bDynAlarm = 0 OR LEN(@arg_dynItemId) <> @lengthDynItemId) BEGIN -- this is a dynamic direct alarm, therefore we can -- take the native received message SET @szDynLamEnglish = @arg_message; END; ELSE BEGIN SET @szDynTextId = N'T02_' + SUBSTRING(@arg_dynItemId,1,4) + N'_' + SUBSTRING(@arg_dynItemId,8,10); IF LEN(@arg_text_id) >= 8 BEGIN -- check whether we the can use directly the text_id to search for the -- corresponding language format string -- we assume that the text_id is valid if the component (4 characters) -- and the text library number (4 characters) are included in the text_id IF (CHARINDEX(SUBSTRING(@arg_dynItemId,1,4), @arg_text_id, 1) > 0 AND CHARINDEX(SUBSTRING(@arg_dynItemId,8,10), @arg_text_id, 1) > 0) BEGIN SET @szDynTextId = @arg_text_id; END; END; SELECT TOP(1) @szDynLamEnglish = [en] FROM [dbo].[DS_LamTexts_TAB] WHERE ([text_id] = @szDynTextId AND [sub_id] = N'MESSAGE') ORDER BY [sub_id] ASC; SELECT @iError = @@ERROR, @iRowCount = @@ROWCOUNT; IF (@iError = 0 AND @iRowCount = 1 AND LEN(ISNULL(@szDynLamEnglish,N'')) > 0) BEGIN SET @bDynParamIndex = 0; SET @sDynStartPos = 1; SET @bDynTagBreak = 0; WHILE (@bDynTagBreak = 0) BEGIN SET @bDynParamIndex = @bDynParamIndex + 1; SET @sDynEndPos = CHARINDEX(N';', @arg_message, @sDynStartPos); IF (@sDynEndPos = 0 OR @sDynEndPos >= 128 OR @bDynParamIndex >= 9) BEGIN SET @sDynEndPos = LEN(@arg_message) + 1; SET @bDynTagBreak = 1; END; SET @szDynToken = N''; IF ((@sDynEndPos - @sDynStartPos) > 0) BEGIN SET @szDynToken = RTRIM(LTRIM(SUBSTRING(@arg_message, @sDynStartPos, @sDynEndPos - @sDynStartPos))); END; IF @bDynParamIndex = 1 BEGIN IF (LEN(@szDynToken) = 3) SET @szDynLamEnglish = REPLACE(@szDynLamEnglish, N'%id', @szDynToken); ELSE SET @szDynLamEnglish = REPLACE(@szDynLamEnglish, N'%id', @arg_deviceId); END; ELSE BEGIN SET @szDynLamEnglish = REPLACE(@szDynLamEnglish, N'%s' + CAST((@bDynParamIndex-1) AS NVARCHAR(16)), @szDynToken); END; SET @sDynStartPos = @sDynEndPos + 1; IF (@sDynStartPos > 128) BEGIN SET @bDynTagBreak = 1; END; END; -- WHILE (@bDynTagBreak = 0) END; --if (@iError = 0 and @iRowCount = 1 and len(isnull(@szDynLamEnglish,0)) > 0) ELSE BEGIN -- there exists no format string for this dynamic alarm -- therefore take the native received message SET @szDynLamEnglish = @arg_message; END; END; -- else of 'IF (@bDynAlarm = 0 OR LEN(@arg_dynItemId) <> 11)' END; --IF (LEN(ISNULL(@arg_message,N'')) > 0) ------------------------------------------------------------------------------- -- Insert a new dataset for the alarm if there is no open alarm registers for this tag -- If an alarm bit is operated by more than one AlarmServer then -- the following constallation can occure: -- AlarmServer 1 inserts a new alarm. This alarm went few seconds later. -- Now AlarmServer 2 process the same alarm and because of this the -- same alarm is stored duplicated in database. The probability of -- this occurance is higher for shorter alarm durations. -- -- Configuration to synchronize multiple AlarmServer with same alarm items -- * DS_GlobalParameter_TAB: set the value to "yes" for parameter -- "SynchronizeMultipleAlarmServer" and category "AlarmServer" -- List of programs which call the procedures DS_SP_AlsAlarmsInsert and DS_SP_AlsAlarmsUpdate -- * the AlarmServer -- - there exists max one AlarmServer per computer -- - there exist max two database connections per AlarmServer (primary and secondary database) -- (the primary and secondary database have to be different) -- - the alarms within the BUF files are processed in FIFO order by the C++ database DLL -- * the procedures DS_SP_PBS_AlarmHandling, DS_SP_WOPC_AlarmHandling -- SELECT TOP(1) @szSyncAlarms = [value] FROM [dbo].[DS_GlobalParameter_TAB] WITH (NOLOCK) WHERE [category] = N'AlarmServer' AND [parameter] = N'SynchronizeMultipleAlarmServer' AND [active] = 1 ORDER BY [id] DESC; IF @@ROWCOUNT = 0 SET @szSyncAlarms = N'no'; IF @szSyncAlarms = N'yes' BEGIN -- Enter critical section BEGIN TRANSACTION; IF EXISTS(SELECT 1 FROM [dbo].[DS_AlsAlarmsExclusiveLock_TAB] [DAAELT] WITH (ROWLOCK XLOCK HOLDLOCK) WHERE [DAAELT].[ionode] = @arg_ionode AND [DAAELT].[ioitem] = @ioitem) BEGIN UPDATE [dbo].[DS_AlsAlarmsExclusiveLock_TAB] WITH (ROWLOCK XLOCK HOLDLOCK) SET [maxDate] = @arg_utc_dts_new_on WHERE [ionode] = @arg_ionode AND [ioitem] = @ioitem AND [maxDate] < @arg_utc_dts_new_on; END; ELSE BEGIN INSERT INTO [dbo].[DS_AlsAlarmsExclusiveLock_TAB]([ionode],[ioitem],[maxDate]) VALUES (@arg_ionode,@ioitem,@arg_utc_dts_new_on); END; SELECT @iError = @@ERROR, @iRowCount = @@ROWCOUNT; COMMIT TRANSACTION; IF @iError <> 0 BEGIN SET @szErrType = N'ERROR'; SET @szErrMsg = N'Can not select from table DS_AlsAlarmsExclusiveLock_TAB for node '+ @arg_ionode + N' and item ' + @ioitem + N';error=' + CAST(@iError AS NVARCHAR(16)); END; IF @iRowCount = 0 BEGIN GOTO afterTransaction; END; END; -- if @szSyncAlarms = N'yes' ELSE BEGIN SELECT @iRowCount = 1, @iError = 0; END; -- write alarm logging IF @iRowCount = 1 AND @iError = 0 BEGIN SET @wtmid = -1; -- get the work time model ID for this alarm IF (@cfg_inst_structure IS NOT NULL) BEGIN SELECT TOP(1) @wtmid = [WTM_ID] FROM [dbo].[DS_CfgInstallationStructure_TAB] WHERE ([ID] = @cfg_inst_structure) ORDER BY [ID] DESC; SELECT @iError = @@ERROR, @iRowCount = @@ROWCOUNT; IF (@iError <> 0 OR @iRowCount <> 1) BEGIN SET @wtmid = -1; END; END; -- if (@cfg_inst_structure is not null) -- get the actual shift number SET @local_dts_new_on = DATEADD(ss,@arg_localTimeDiff,@arg_utc_dts_new_on); EXEC @shiftnr = [dbo].[DS_SP_GetShiftDetailsForDateEvt] @local_dts_new_on, @wtmid, @tTypIdOfShift OUTPUT, 1; -- 2022-10-20, debiezala -- use merge instead of insert to prevent double entries -- independant when how many AlarmServers are running MERGE INTO [dbo].[DS_AlsAlarms_TAB] AS [t] USING (VALUES (@arg_ionode, @ioitem) ) AS [s] ([ionode], [ioitem]) ON ([t].[ionode] = [s].[ionode] AND [t].[ioitem] = [s].[ioitem] AND [t].[utc_dts_gone_off] IS NULL) WHEN NOT MATCHED THEN INSERT ([utc_dts_new_on], [local_dts_new_on], [shift_nr], [computer], [text_id], [ionode], [ioitem], [message], [priority], [areakey], [plant_type], [class]) VALUES (@arg_utc_dts_new_on, @local_dts_new_on, @shiftnr, @arg_computer, @arg_text_id, @arg_ionode, @ioitem, @szDynLamEnglish, ISNULL(@iAlsTagsPriority, @arg_priority), @areakey, @plant_type, @class); SELECT @iError = @@ERROR, @iRowCount = @@ROWCOUNT; IF @iError <> 0 BEGIN SET @szErrType = N'ERROR'; SET @szErrMsg = N'Can not insert alarm message for node '+ @arg_ionode + N' and item ' + @ioitem + N';error=' + CAST(@iError AS NVARCHAR(16)) + N';row count=' + CAST(@iRowCount AS NVARCHAR(16)); GOTO afterTransaction; END; END; -- if @iRowCount = 0 and @iError = 0 afterTransaction: IF @szErrMsg <> N'' BEGIN EXEC [dbo].[DS_SP_WriteToDSErrorLog] @procName, @szErrType, @szErrMsg; END; RETURN 1; END; 分析以上存储过程
07-30
内容概要:本文设计了一种基于PLC的全自动洗衣机控制系统内容概要:本文设计了一种,采用三菱FX基于PLC的全自动洗衣机控制系统,采用3U-32MT型PLC作为三菱FX3U核心控制器,替代传统继-32MT电器控制方式,提升了型PLC作为系统的稳定性与自动化核心控制器,替代水平。系统具备传统继电器控制方式高/低水,实现洗衣机工作位选择、柔和过程的自动化控制/标准洗衣模式切换。系统具备高、暂停加衣、低水位选择、手动脱水及和柔和、标准两种蜂鸣提示等功能洗衣模式,支持,通过GX Works2软件编写梯形图程序,实现进洗衣过程中暂停添加水、洗涤、排水衣物,并增加了手动脱水功能和、脱水等工序蜂鸣器提示的自动循环控制功能,提升了使用的,并引入MCGS组便捷性与灵活性态软件实现人机交互界面监控。控制系统通过GX。硬件设计包括 Works2软件进行主电路、PLC接梯形图编程线与关键元,完成了启动、进水器件选型,软件、正反转洗涤部分完成I/O分配、排水、脱、逻辑流程规划水等工序的逻辑及各功能模块梯设计,并实现了大形图编程。循环与小循环的嵌; 适合人群:自动化套控制流程。此外、电气工程及相关,还利用MCGS组态软件构建专业本科学生,具备PL了人机交互C基础知识和梯界面,实现对洗衣机形图编程能力的运行状态的监控与操作。整体设计涵盖了初级工程技术人员。硬件选型、; 使用场景及目标:I/O分配、电路接线、程序逻辑设计及组①掌握PLC在态监控等多个方面家电自动化控制中的应用方法;②学习,体现了PLC在工业自动化控制中的高效全自动洗衣机控制系统的性与可靠性。;软硬件设计流程 适合人群:电气;③实践工程、自动化及相关MCGS组态软件与PLC的专业的本科生、初级通信与联调工程技术人员以及从事;④完成PLC控制系统开发毕业设计或工业的学习者;具备控制类项目开发参考一定PLC基础知识。; 阅读和梯形图建议:建议结合三菱编程能力的人员GX Works2仿真更为适宜。; 使用场景及目标:①应用于环境与MCGS组态平台进行程序高校毕业设计或调试与运行验证课程项目,帮助学生掌握PLC控制系统的设计,重点关注I/O分配逻辑、梯形图与实现方法;②为工业自动化领域互锁机制及循环控制结构的设计中类似家电控制系统的开发提供参考方案;③思路,深入理解PL通过实际案例理解C在实际工程项目PLC在电机中的应用全过程。控制、时间循环、互锁保护、手动干预等方面的应用逻辑。; 阅读建议:建议结合三菱GX Works2编程软件和MCGS组态软件同步实践,重点理解梯形图程序中各环节的时序逻辑与互锁机制,关注I/O分配与硬件接线的对应关系,并尝试在仿真环境中调试程序以加深对全自动洗衣机控制流程的理解。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值