各种字符串到日期。 [英] Various strings to dates.

查看:73
本文介绍了各种字符串到日期。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这个论坛上看到过关于此事的一些信息,但我的谷歌搜索

并没有找到我想要的答案。


我有一个元组列表。每个元组的格式如下:


(data,moredata,evenmoredata,日期字符串)


日期字符串是我关注的问题。这是电子邮件中的日期戳。

问题是,当涉及日期字符串所在的

格式时,我有很多变化。例如我可以有以下

两个元组:


(data,moredata,evenmoredata,Fri,23 2004年1月00:06:15

(data,moredata,evenmoredata,2004年1月22日星期四03:15:06)


我知道有一些方法可以使用每个日期字符串来获得python可用的

日期,但我无法弄明白。

我试图使用time.strptime但到目前为止已经不成功了。


感谢任何帮助。

I have seen something about this beofore on this forum, but my google search
didn''t come up with the answer I am looking for.

I have a list of tuples. Each tuple is in the following format:

("data", "moredata", "evenmoredata", "date string")

The date string is my concern. This is the date stamp from an email.
The problem is that I have a whole bunch of variations when it comes to the
format that the date string is in. For example I could have the following
two tuples:

("data", "moredata", "evenmoredata", "Fri, 23 Jan 2004 00:06:15")
("data", "moredata", "evenmoredata", "Thursday, 22 January 2004 03:15:06")

I know there is some way to use the date string from each of these to get a
date usable by python, but I cannot figure it out.
I was trying to use time.strptime but have been unsuccesful thus far.

Any help is appreciated.

推荐答案

Amy,

我希望有更好的方法但是,如果你去这里:

ht tp://www.python.org/doc/current/li...time-date.html

新的日期时间模块可能有所帮助。这个和时间mod

可以让你到达你想去的地方。


list = strdate.split(",")

daystr = list [0]

daynum = int(list [1])

monthstr = list [2]

year = int(list [3])

#funct需要一个月的int


d = datetime.Date(y,m,d)


wes


--------------------------- ------------


Amy G写道:
Amy,
I hope there is a better way but, if you go here:

http://www.python.org/doc/current/li...time-date.html

The new datetime module may help. This and the time mod
should get you where you want to go.

list = strdate.split(", ")
daystr = list[0]
daynum = int(list[1])
monthstr = list[2]
year = int(list[3])
#funct to get a month int is needed

d = datetime.Date(y,m,d)

wes

---------------------------------------

Amy G wrote:
我在这个论坛上看到了关于这个beofore的东西,但是我的谷歌搜索
没有找到我想要的答案。

我有一个元组列表。每个元组的格式如下:

(data,moredata,evenmoredata,日期字符串)

日期字符串是我的顾虑。这是来自电子邮件的日期戳。
问题是,当涉及到日期字符串所在的
格式时,我有很多变化。例如,我可以拥有以下内容两个元组:

(data,moredata,evenmoredata,Fri,2004年1月23日00:06:15)
(" data,moredata",evenmoredata,2004年1月22日星期四03:15:06)

我知道有一些方法可以使用这些中的每一个的日期字符串得到一个可以被python使用的日期,但是我无法弄明白。
我试图使用time.strptime但到目前为止已经不成功了。

任何帮助都表示赞赏。
I have seen something about this beofore on this forum, but my google search
didn''t come up with the answer I am looking for.

I have a list of tuples. Each tuple is in the following format:

("data", "moredata", "evenmoredata", "date string")

The date string is my concern. This is the date stamp from an email.
The problem is that I have a whole bunch of variations when it comes to the
format that the date string is in. For example I could have the following
two tuples:

("data", "moredata", "evenmoredata", "Fri, 23 Jan 2004 00:06:15")
("data", "moredata", "evenmoredata", "Thursday, 22 January 2004 03:15:06")

I know there is some way to use the date string from each of these to get a
date usable by python, but I cannot figure it out.
I was trying to use time.strptime but have been unsuccesful thus far.

Any help is appreciated.






不,它不会。不幸的是,我不一定要用逗号分隔日期

string。感谢您的输入。


以下三个日期字符串是我将在这里遇到的各种日期

格式的另一个例子。


2004年1月22日星期四03:15:06

2004年1月22日星期四,03:15:06

2004年1月22日星期四03:15:06


所有这些基本上都是相同的日期...只是各种格式。我想要解析它们并获得可比较的格式,以便我可以按时间顺序显示它们。

" wes weston" ; < WW ***** @ att.net>在消息中写道

新闻:MF ********************* @ bgtnsc05-news.ops.worldnet.att.net ...
No it won''t. Unfortunatly I don''t necessarily have a comma delimited date
string. Thanks for the input though.

The following three date strings is another example of the various date
formats I will encounter here.

Thursday, 22 January 2004 03:15:06
Thursday, January 22, 2004, 03:15:06
2004, Thursday, 22 January 03:15:06

All of these are essentially the same date... just in various formats. I
would like to parse through them and get a comparable format so that I can
display them in chronological order.
"wes weston" <ww*****@att.net> wrote in message
news:MF*********************@bgtnsc05-news.ops.worldnet.att.net...
艾米,
我希望有更好的方法但是,如果你去这里:

http://www.python.org/doc/current/li...time-date.html

新的日期时间模块可能有所帮助。这个和时间mod
可以让你到达你想去的地方。

list = strdate.split(",")
daystr = list [0]
daynum = int(list [1])
monthstr = list [2]
year = int(list [3])
要获得一个月int的#funct

d = datetime.Date(y,m,d)

wes

---------------- -----------------------

Amy G写道:
Amy,
I hope there is a better way but, if you go here:

http://www.python.org/doc/current/li...time-date.html

The new datetime module may help. This and the time mod
should get you where you want to go.

list = strdate.split(", ")
daystr = list[0]
daynum = int(list[1])
monthstr = list[2]
year = int(list[3])
#funct to get a month int is needed

d = datetime.Date(y,m,d)

wes

---------------------------------------

Amy G wrote:
我见过这个关于这个的事情在这个论坛上,但我的谷歌
搜索没有找到我想要的答案。

我有一个元组列表。每个元组的格式如下:

(data,moredata,evenmoredata,日期字符串)

日期字符串是我的顾虑。这是来自电子邮件的日期戳。
问题是,当涉及日期字符串所在的格式
时,我有一大堆变体。例如,我可以拥有
跟随两个元组:

(data,moredata,evenmoredata,Fri,2004年1月23日00:06:15)
(" data,moredata",evenmoredata,2004年1月22日星期四
03:15:06)
我知道有一些方法可以使用这些中的每一个的日期字符串到
得到python可以使用的日期,但我无法理解。
我试图使用time.strptime但到目前为止一直没有用。

任何帮助表示赞赏。
I have seen something about this beofore on this forum, but my google search didn''t come up with the answer I am looking for.

I have a list of tuples. Each tuple is in the following format:

("data", "moredata", "evenmoredata", "date string")

The date string is my concern. This is the date stamp from an email.
The problem is that I have a whole bunch of variations when it comes to the format that the date string is in. For example I could have the following two tuples:

("data", "moredata", "evenmoredata", "Fri, 23 Jan 2004 00:06:15")
("data", "moredata", "evenmoredata", "Thursday, 22 January 2004 03:15:06")
I know there is some way to use the date string from each of these to get a date usable by python, but I cannot figure it out.
I was trying to use time.strptime but have been unsuccesful thus far.

Any help is appreciated.



" Amy G" <是******* @ cox.net>在消息中写道

news:PRgQb.16209
"Amy G" <am*******@cox.net> wrote in message
news:PRgQb.16209


这篇关于各种字符串到日期。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆