Created
October 1, 2013 12:19
-
-
Save bayadeoro/6777608 to your computer and use it in GitHub Desktop.
Python: Script de python que insertar una fecha en una tabla de la bbdd indicándole la zona horaria
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| bombadil@barbol:~/Proyectos/miprimerproyecto$ python manage.py shell | |
| >>> from polls.models import Poll, Choice | |
| >>> Poll.objects.all() | |
| [] | |
| >>> # Creamos una nueva encuesta | |
| >>> from datetime import datetime | |
| >>> p = Poll(question="Como estas?", pub_date=datetime.now()) | |
| >>> # Guardamos el objeto | |
| >>> p.save() | |
| >>> p.id | |
| 1 | |
| >>> p.question | |
| 'Como estas?' | |
| >>> p.pub_date | |
| >>> from django.utils.timezone import utc | |
| >>> p.pub_date = datetime.utcnow().replace(tzinfo=utc) | |
| >>> p.save() | |
| >>> p.pub_date = datetime(2013, 9, 2, 6, 45, 41, 359604) | |
| >>> import pytz | |
| >>> madrid_tz = pytz.timezone("Europe/Madrid") | |
| >>> madrid_tz.localize(datetime(2013, 9, 2, 6, 45, 41, 359604)) | |
| datetime.datetime(2013, 9, 2, 6, 45, 41, 359604, tzinfo=<DstTzInfo 'Europe/Madrid' CEST+2:00:00 DST>) | |
| >>> p.pub_date = madrid_tz.localize(datetime(2013, 9, 2, 6, 45, 41, 359604)) | |
| >>> p.save() | |
| >>> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment