Ho questa stringa '2015-04-08T07:52:00Z'
e voglio convertirla in '08/04/2015'
, come posso fare questo?Come faccio a convertire da timestamp ad oggi in python?
risposta
È possibile utilizzare la funzione datetime.datetime.strptime()
per creare un oggetto di tipo datetime, quindi datetime.datetime.strftime()
di restituire la data correttamente formattata in questo modo:
from datetime import datetime
dt = datetime.strptime('2015-04-08T07:52:00Z', '%Y-%m-%dT%H:%M:%SZ')
print dt.strftime('%d/%m/%Y')
Grazie mille signore! ^^ –
Ciò significa fare clic sul segno di spunta sotto il triangolo capovolto sulla sinistra. –
Ecco un buon cheatsheet per strftime - http://strftime.org – Zaffiro
È possibile utilizzare easy_date per rendere più facile:
import date_converter
converted_date = date_converter.string_to_string('2015-04-08T07:52:00Z', '%Y-%m-%dT%H:%M:%SZ', '%d/%m/%Y')
dovresti probabilmente usare un singolo namespace es., 'Easy_date.string_to_string' (crea un pacchetto e importa i nomi corrispondenti, vedi come [' asyncio'] (https : //hg.python.org/cpython/file/9dfda4e7169a/Lib/asyncio/__init__.py) o 'numpy' fallo). – jfs
- 1. Python convertire lungo fino ad oggi
- 2. Come convertire un timestamp unix fino ad oggi in Spark
- 3. Postgres: come convertire da unix epoca ad oggi?
- 4. VBA convertire la stringa fino ad oggi
- 5. come convertire stringa fino ad oggi oggetto in Ruby
- 6. parsing della stringa data in python (convertire la stringa ad oggi)
- 7. Come convertire la stringa timestamp di Python in epoch?
- 8. Convertire epoca fino ad oggi in sqlplus/Oracle
- 9. Converti stringa Fino ad oggi in PHP
- 10. Domanda Python: anno e giorno dell'anno fino ad oggi?
- 11. Golang: Data String ad oggi
- 12. Come aggiungere settimane ad oggi usando javascript?
- 13. Come posso ottenere timestamp di oggi in PHP
- 14. Python statistiche: Come faccio a scrivere ad un (leggibile) file
- 15. Convertire questa stringa a timestamp PHP
- 16. Come faccio a convertire la data in Netezza per yyyymmdd dal formato timestamp
- 17. convertire unix timestamp in H2 timestamp
- 18. Come faccio a confrontare due timestamp in C?
- 19. da unix timestamp a datetime
- 20. Come convertire il timestamp DB2 in datetime?
- 21. Come convertire datetime() in timestamp() in erlang
- 22. Come convertire le stringhe come "19-FEB-12" ad oggi epoca in UNIX
- 23. Numero di settimana di conversione ad oggi
- 24. Convertire unix timestamp a JavaScript Object data
- 25. Set MinDate ad oggi in Bootstrap DateTimePicker
- 26. Convertire timestamp Unix a ISO 8601
- 27. Converti Stringa facoltativa fino ad oggi
- 28. Come posso convertire da esadecimale a decimale in Python?
- 29. Convertire timestamp Unix in datetime
- 30. Python convertire tuple a stringa
[ Rappresentazione di data e ora in Python] (http://www.seehuhn.de/pages/pdate) –
correlati: [Come analizzare la data ISO formattata in python?] (Http://stackoverflow.com/q/127803/4279) – jfs