简体   繁体   English

集成到 Oracle PMS 时出现日期解析问题

[英]Date Parsing problem while Integrating to Oracle PMS

I'm recieving date in PMS message something like this |GA090616|GD090617|我在 PMS 消息中收到类似这样的日期|GA090616|GD090617| which means Guest Arrival is at 09-06-16 and Guest Deprature is at 09-06-17这意味着客人到达时间为 09-06-16,客人下车时间为 09-06-17

I wanted to parse it as date using python.我想使用 python 将其解析为日期。

I've also visited stack oveflow[ 1 , 2 ... ] for this but as solution I've found为此,我还访问了 stack oveflow[ 1 , 2 ... ] 但作为解决方案,我找到了

from datetime import datetime

self.DATE_FROMAT='%d/%m/%y'

arrival_date=datetime.strptime('90616', self.DATE_FROMAT).date()
print(arrival_date)

and it's not possible to parse it like this due to its unclear format.由于格式不明确,无法像这样解析它。 I'm not sure if 09 is a month or a date, but from what I've seen in documents and PDFs, it appears to be a month.我不确定 09 是月份还是日期,但根据我在文档和 PDF 中看到的内容,它似乎是一个月。

Is there any better solution for this kind of date parsing?这种日期解析有更好的解决方案吗? or suggestions for my expectations.或对我的期望的建议。

09-06-16,
09-06-17

Note: Please Just take the date from the string 090617 and parse it as a date.注意:请从字符串090617中取出日期并将其解析为日期。 That will be helpful.那会很有帮助。

You can do this with regex matching, you can either split the string with msg.split("|") or not, but that depends on your use case.您可以使用正则表达式匹配来执行此操作,您可以使用 msg.split("|") 拆分字符串,也可以不使用,但这取决于您的用例。

import re
from datetime import datetime

msg = "GA090616|GD090617|"
DATE_FORMAT='%d%m%y'

ar = re.match("GA(\d{6})", msg)
dp = re.match("GD(\d{6})", msg)

guest_arrival = datetime.strptime(ar.group(1), DATE_FORMAT).date()
guest_departure = datetime.strptime(dp.group(1), DATE_FORMAT).date()

Although not fully tested, this should be a boilerplate as to how to retrieve the date from the message.虽然没有经过全面测试,但这应该是关于如何从消息中检索日期的样板。 Remember to remove the \ from the date format, as that is not included in the message.请记住从日期格式中删除\ ,因为它不包含在消息中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2025 STACKOOM.COM