|
| 1 | +# |
| 2 | +#EJERCICIO: |
| 3 | +#Crea dos variables utilizando los objetos fecha (date, o semejante) de tu lenguaje: |
| 4 | +#- Una primera que represente la fecha (día, mes, año, hora, minuto, segundo) actual. |
| 5 | +#- Una segunda que represente tu fecha de nacimiento (te puedes inventar la hora). |
| 6 | +#Calcula cuántos años han transcurrido entre ambas fechas. |
| 7 | +# |
| 8 | +#DIFICULTAD EXTRA (opcional): |
| 9 | +#Utilizando la fecha de tu cumpleaños, formatéala y muestra su resultado de |
| 10 | +#10 maneras diferentes. Por ejemplo: |
| 11 | +#- Día, mes y año. |
| 12 | +#- Hora, minuto y segundo. |
| 13 | +#- Día de año. |
| 14 | +#- Día de la semana. |
| 15 | +#- Nombre del mes. |
| 16 | +#(lo que se te ocurra...) |
| 17 | +# |
| 18 | +from datetime import datetime, date |
| 19 | + |
| 20 | +now = datetime.now() |
| 21 | +birth = datetime.strptime("25/05/1978 09:13:27", "%d/%m/%Y %H:%M:%S") |
| 22 | +time_elapsed = now.year - birth.year |
| 23 | +print(f"Desde {birth} hasta {now} han pasado {time_elapsed} años.") |
| 24 | +print(f"{datetime.strftime(birth, "%d/%m/%Y")}") |
| 25 | +print(f"{datetime.strftime(birth, "%H/%M/%S")}") |
| 26 | +print(f"{datetime.isocalendar(birth)}") |
| 27 | +print(f"{datetime.timestamp(birth)}") |
| 28 | +print(f"{datetime.timetz(birth)}") |
| 29 | +print(f"{datetime.timetuple(birth)}") |
| 30 | +print(f'{datetime.astimezone(birth)}') |
| 31 | +print(f'{datetime.dst(birth)}') |
| 32 | +print(f'{datetime.isoformat(birth, "H", 'minutes')}') |
| 33 | +print(f'{datetime.toordinal(birth)}') |
| 34 | +print(f'{datetime.weekday(birth)}') |
0 commit comments