# Getting the current time in Python

**URL:** <https://blenderartists.org/t/getting-the-current-time-in-python/392447>\
**Category:** Python Support\
**Created:** [June 23, 2007, 9:31am UTC](https://blenderartists.org/t/getting-the-current-time-in-python/392447 "2007-06-23T09:31:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![animatinator](https://blenderartists.org/user_avatar/blenderartists.org/animatinator/32/4544_2.png) [@animatinator](https://blenderartists.org/u/animatinator)\
**Post date:** [June 23, 2007, 9:31am UTC](https://blenderartists.org/t/getting-the-current-time-in-python/392447/1 "2007-06-23T09:31:00Z")

</div>

Is there any way to get the current time off the system clock with Python? I’ve done several searches and have managed to get it to print the date and time as one string:

```auto
import datetime
print datetime.datetime.now()

```

which gives “2007-06-23 17:32:16.906000”. Is there a way of splitting that up so I can get the hours, minutes and seconds as separate numbers?

---

<div class="post-metadata">

**Author:** ![ideasman42](https://blenderartists.org/user_avatar/blenderartists.org/ideasman42/32/900508_2.png) [@ideasman42](https://blenderartists.org/u/ideasman42)\
**Post date:** [June 23, 2007, 10:04am UTC](https://blenderartists.org/t/getting-the-current-time-in-python/392447/2 "2007-06-23T10:04:00Z")

</div>

This is really a python only question, whilst its great people here are willing to help on a wide range of issues, you could probably google this one? Im sure there are online docs for this kinda stuff.

---

<div class="post-metadata">

**Author:** ![rgrady](https://blenderartists.org/letter_avatar_proxy/v4/letter/r/a8b319/32.png) [@rgrady](https://blenderartists.org/u/rgrady)\
**Post date:** [June 29, 2007, 12:12pm UTC](https://blenderartists.org/t/getting-the-current-time-in-python/392447/3 "2007-06-29T12:12:25Z")

</div>

Try

```auto
&gt;&gt;&gt; import time
&gt;&gt;&gt; time.localtime()
(2007, 6, 29, 14, 9, 57, 4, 180, 1)
&gt;&gt;&gt; time.localtime()[1]
6

```

The output is: year, month, day, hour, minute, second, weekday number (Monday=0), day (by year), daylight savings time flag )

---

<div class="post-metadata">

**Author:** ![animatinator](https://blenderartists.org/user_avatar/blenderartists.org/animatinator/32/4544_2.png) [@animatinator](https://blenderartists.org/u/animatinator)\
**Post date:** [June 29, 2007, 2:18pm UTC](https://blenderartists.org/t/getting-the-current-time-in-python/392447/4 "2007-06-29T14:18:53Z")

</div>

Thanks, now I see how to do it:D I didn’t know you could get it as a list, the documentation’s quite confusing:o

---

<div class="post-metadata">

**Author:** ![rgrady](https://blenderartists.org/letter_avatar_proxy/v4/letter/r/a8b319/32.png) [@rgrady](https://blenderartists.org/u/rgrady)\
**Post date:** [July 5, 2007, 9:31am UTC](https://blenderartists.org/t/getting-the-current-time-in-python/392447/5 "2007-07-05T09:31:26Z")

</div>

My pleasure. And yes, I sometimes find the Python docs to be confusing, or at least, not as descriptive as I’d like. So usually when I’m looking for a function I search the docs and when I find something that might work, I try it in the Python interpreter. For example, when looking this up, I googled for ‘python current time’. The first hit was [http://docs.python.org/lib/module-time.html](http://docs.python.org/lib/module-time.html). I looked through there and found the localtime() method, but there was no description of the output. So I fired up the Python interpreter and tried it out.
