Events 在本地时间解析IBM MQ事件监视消息

Events 在本地时间解析IBM MQ事件监视消息,events,timezone,ibm-mq,gmt,Events,Timezone,Ibm Mq,Gmt,我正在使用IBM提供的示例程序amqsevt监视MQ事件队列并解析消息。但我注意到,默认情况下,事件创建时间以GMT时间表示。我想把它转换成系统本地时间。有没有办法做到这一点 **** Message #1 (120 Bytes) on Queue SYSTEM.ADMIN.CHANNEL.EVENT **** Event Type : Channel Event [46] Reason : Chan

我正在使用IBM提供的示例程序amqsevt监视MQ事件队列并解析消息。但我注意到,默认情况下,事件创建时间以GMT时间表示。我想把它转换成系统本地时间。有没有办法做到这一点

**** Message #1 (120 Bytes) on Queue SYSTEM.ADMIN.CHANNEL.EVENT ****
Event Type                       : Channel Event [46]
Reason                           : Channel Stopped By User [2279]
Event created                    : 2018/09/04 20:17:39.48 GMT

示例的源代码可以在Linux上找到,MQ安装在
/opt/mqm
/opt/mqm/samp/amqsevta.c

在每条消息的
MQMD
(消息描述符)中有一个
PutDate
PutTime
字段,该字段始终存储在GMT中,每个字段都是简单的8位字符串,例如:

  • 提交日期:20180904(YYYYMMDD)
  • 发布时间:20173948(hhmmsss)
在示例程序中,它只是将其转换为显示格式
2018/09/04 20:17:39.48
,并将
GMT
附加到末尾,因为它知道这始终是在GMT中

  /**********************************************************/
  /* Timestamp is read from the MQMD - it is always in GMT  */
  /* regardless of local timezone. Do not want to try to    */
  /* convert it, because this machine may be a client in a  */
  /* different timezone than the server generating the      */
  /* event. So stick to GMT (or UCT if you prefer).         */
  /**********************************************************/
  sprintf(valbuf,"%4.4s/%2.2s/%2.2s %2.2s:%2.2s:%2.2s.%2.2s GMT",
     &pMsgDesc->PutDate[0],
     &pMsgDesc->PutDate[4],
     &pMsgDesc->PutDate[6],
     &pMsgDesc->PutTime[0],
     &pMsgDesc->PutTime[2],
     &pMsgDesc->PutTime[4],
     &pMsgDesc->PutTime[6]);
  printLine(offset,"Event created",valbuf);

看起来您可以使用c函数
strtime
将字符串解析为历元时间戳,然后在本地时区打印该时间戳。

我建议更改并重新编译示例程序,使其以您喜欢的格式输出日期。请注意,在Mark Taylor关于事件主题的博客文章中,他发布了一个可输出JSON格式的修改版本,该版本现在包含在9.1.0.0版本中,这可能是一种更容易输入监控工具的格式。