“Konversi tanggal menjadi string di Python” Kode Jawaban

datetime ke string python

import datetime
t = datetime.datetime(2012, 2, 23, 0, 0)
t.strftime('%m/%d/%Y')
Juan David Morales Navarrete

datetime ke string python

from datetime import datetime

now = datetime.now() # current date and time

year = now.strftime("%Y")
print("year:", year)

month = now.strftime("%m")
print("month:", month)

day = now.strftime("%d")
print("day:", day)

time = now.strftime("%H:%M:%S")
print("time:", time)

date_time = now.strftime("%m/%d/%Y, %H:%M:%S")
print("date and time:",date_time)
Powerful Partridge

Konversi tanggal menjadi string di Python

# import the date class
from datetime import date

# function of date class
today = date.today()

# Converting the date to the string
Str = date.isoformat(today)
print("String Representation", Str)
print(type(Str))
Outrageous Ostrich

Konversi tanggal menjadi string di Python

# You can use Numpy's datetime_as_string function.
# The unit='D' argument specifies the precision, in this case days.

t = numpy.datetime64('2012-06-30T20:00:00.000000000-0400')
numpy.datetime_as_string(t, unit='D')

Mckynde

Jawaban yang mirip dengan “Konversi tanggal menjadi string di Python”

Pertanyaan yang mirip dengan “Konversi tanggal menjadi string di Python”

Lebih banyak jawaban terkait untuk “Konversi tanggal menjadi string di Python” di Python

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya