English 中文(简体)
我如何转换一个日期?
原标题:How do I convert a datetime to date?

我如何将<条码>日志>改为<条码>日值>。 反对:

最佳回答

Use the 方法:

datetime.datetime.now().date()
问题回答

文件:

datetime.date(

返回日期同年、月和日。

您使用<代码>最新时间。

datetime.datetime.now().date()

很明显,上述表述可以(而且应当:)写成:

datetime.date.today()

2. 您可将某一日标改为日标的(日期)方法,具体如下:

<datetime_object>.date()

you could enter this code form for (today date & Names of the Day & hour) : datetime.datetime.now().strftime( %y-%m-%d %a %H:%M:%S )

19-09-09 Mon 17:37.56

and enter this code for (today date simply): datetime.date.today().strftime( %y-%m-%d ) 19-09-10

for object : datetime.datetime.now().date() datetime.datetime.today().date() datetime.datetime.utcnow().date() datetime.datetime.today().time() datetime.datetime.utcnow().date() datetime.datetime.utcnow().time()

www.un.org/Depts/DGACM/index_spanish.htm 对3.7和的答复

这里,你可以提出日期和时间目标。

(aka <代码>datetime 物体,储存在models.Datetime。 django模型领域

日标(aka datetime.date Object):

from datetime import datetime

#your date-and-time object
# let s supposed it is defined as
datetime_element = datetime(2020, 7, 10, 12, 56, 54, 324893)

# where
# datetime_element = datetime(year, month, day, hour, minute, second, milliseconds)

# WHAT YOU WANT: your date-only object
date_element = datetime_element.date()

简言之,如果你印刷这些内容,这里的产出就是:

print(datetime_element)

207-10 12:56:54.324893


print(date_element)

2008年6月30日

import time
import datetime

# use mktime to step by one day
# end - the last day, numdays - count of days to step back
def gen_dates_list(end, numdays):
  start = end - datetime.timedelta(days=numdays+1)
  end   = int(time.mktime(end.timetuple()))
  start = int(time.mktime(start.timetuple()))
  # 86400 s = 1 day
  return xrange(start, end, 86400)

# if you need reverse the list of dates
for dt in reversed(gen_dates_list(datetime.datetime.today(), 100)):
    print datetime.datetime.fromtimestamp(dt).date()
Solved: AttributeError:  Series  object has no attribute  date 

您可使用如下:

df["date"] = pd.to_datetime(df["date"]).dt.date

在以上编码日期既包括日期,又包括时间(2020-09-21 22:32:00)的地方,使用上述代码,我们只能获得日期(2020-09-21)。

I use data.strftime (%y-%m-%d ) with lambda to transfer一栏

如果你使用<pandas>,就可以解决这个问题:

请允许我说,你有了一个称为起步的变量——在你的数据框架内的类型时间64,这样你就可以获得这样的日期:

df.start_time.dt.date




相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签