Hướng dẫn convert int to time python - chuyển đổi int thành trăn thời gian

Có thể chuyển đổi int thành giờ không: Min: Sec

Show
import datetime 

x = 40000 

t = int(x) 

day = t//86400 
hour = (t-(day*86400))//3600 
min = (t - ((day*86400) + (hour*3600)))//60 
seconds = t - ((day*86400) + (hour*3600) + (min*60)) 

hello= datetime.time(hour.hour, min.minute, seconds.second)   

print (hello )

Tôi muốn đầu ra này:- 11:06:40

Hỏi ngày 18 tháng 12 năm 2017 lúc 15:12Dec 18, 2017 at 15:12

Hướng dẫn convert int to time python - chuyển đổi int thành trăn thời gian

Bạn cũng có thể thuê ngoài tất cả các hoạt động phân chia và modulo cho các bản dựng Python (hãy nhớ: bao gồm pin!)

>>> import time
>>> x = 40000 
>>> time.strftime('%H:%M:%S', time.gmtime(x))
'11:06:40'                    # <- that's your desired output
>>> time.gmtime(x)
time.struct_time(tm_year=1970, tm_mon=1, tm_mday=1, tm_hour=11, tm_min=6, tm_sec=40, tm_wday=3, tm_yday=1, tm_isdst=0)
>>> time.gmtime(x).tm_hour    # <- that's how to access individual values
11

Đã trả lời ngày 18 tháng 12 năm 2017 lúc 15:31Dec 18, 2017 at 15:31

PavelpavelPavel

7.2462 Huy hiệu vàng28 Huy hiệu bạc42 Huy hiệu đồng2 gold badges28 silver badges42 bronze badges

Bạn gần như đã nhận được nó.

hour,

>>> import time
>>> x = 40000 
>>> time.strftime('%H:%M:%S', time.gmtime(x))
'11:06:40'                    # <- that's your desired output
>>> time.gmtime(x)
time.struct_time(tm_year=1970, tm_mon=1, tm_mday=1, tm_hour=11, tm_min=6, tm_sec=40, tm_wday=3, tm_yday=1, tm_isdst=0)
>>> time.gmtime(x).tm_hour    # <- that's how to access individual values
11
0 và
>>> import time
>>> x = 40000 
>>> time.strftime('%H:%M:%S', time.gmtime(x))
'11:06:40'                    # <- that's your desired output
>>> time.gmtime(x)
time.struct_time(tm_year=1970, tm_mon=1, tm_mday=1, tm_hour=11, tm_min=6, tm_sec=40, tm_wday=3, tm_yday=1, tm_isdst=0)
>>> time.gmtime(x).tm_hour    # <- that's how to access individual values
11
1 là số nguyên và số nguyên không có các thuộc tính hour,
>>> import time
>>> x = 40000 
>>> time.strftime('%H:%M:%S', time.gmtime(x))
'11:06:40'                    # <- that's your desired output
>>> time.gmtime(x)
time.struct_time(tm_year=1970, tm_mon=1, tm_mday=1, tm_hour=11, tm_min=6, tm_sec=40, tm_wday=3, tm_yday=1, tm_isdst=0)
>>> time.gmtime(x).tm_hour    # <- that's how to access individual values
11
3 hoặc
>>> import time
>>> x = 40000 
>>> time.strftime('%H:%M:%S', time.gmtime(x))
'11:06:40'                    # <- that's your desired output
>>> time.gmtime(x)
time.struct_time(tm_year=1970, tm_mon=1, tm_mday=1, tm_hour=11, tm_min=6, tm_sec=40, tm_wday=3, tm_yday=1, tm_isdst=0)
>>> time.gmtime(x).tm_hour    # <- that's how to access individual values
11
4.

Biến đổi

hello = datetime.time(hour.hour, min.minute, seconds.second)

đến

hello = datetime.time(hour, min, seconds)

Như một lưu ý phụ,

>>> import time
>>> x = 40000 
>>> time.strftime('%H:%M:%S', time.gmtime(x))
'11:06:40'                    # <- that's your desired output
>>> time.gmtime(x)
time.struct_time(tm_year=1970, tm_mon=1, tm_mday=1, tm_hour=11, tm_min=6, tm_sec=40, tm_wday=3, tm_yday=1, tm_isdst=0)
>>> time.gmtime(x).tm_hour    # <- that's how to access individual values
11
5 hoàn toàn không cần thiết vì
>>> import time
>>> x = 40000 
>>> time.strftime('%H:%M:%S', time.gmtime(x))
'11:06:40'                    # <- that's your desired output
>>> time.gmtime(x)
time.struct_time(tm_year=1970, tm_mon=1, tm_mday=1, tm_hour=11, tm_min=6, tm_sec=40, tm_wday=3, tm_yday=1, tm_isdst=0)
>>> time.gmtime(x).tm_hour    # <- that's how to access individual values
11
6 đã là một
>>> import time
>>> x = 40000 
>>> time.strftime('%H:%M:%S', time.gmtime(x))
'11:06:40'                    # <- that's your desired output
>>> time.gmtime(x)
time.struct_time(tm_year=1970, tm_mon=1, tm_mday=1, tm_hour=11, tm_min=6, tm_sec=40, tm_wday=3, tm_yday=1, tm_isdst=0)
>>> time.gmtime(x).tm_hour    # <- that's how to access individual values
11
7.

Như một lưu ý phụ 2, trong tương lai, vui lòng cung cấp lỗi bạn nhận được.

Đã trả lời ngày 18 tháng 12 năm 2017 lúc 15:15Dec 18, 2017 at 15:15

DeepSpacedeepspaceDeepSpace

74,8K11 Huy hiệu vàng100 Huy hiệu bạc142 Huy hiệu đồng11 gold badges100 silver badges142 bronze badges

Lưu ý: Đáp lại câu trả lời của @pavel,

Bạn có thể tìm thấy

>>> import time
>>> x = 40000 
>>> time.strftime('%H:%M:%S', time.gmtime(x))
'11:06:40'                    # <- that's your desired output
>>> time.gmtime(x)
time.struct_time(tm_year=1970, tm_mon=1, tm_mday=1, tm_hour=11, tm_min=6, tm_sec=40, tm_wday=3, tm_yday=1, tm_isdst=0)
>>> time.gmtime(x).tm_hour    # <- that's how to access individual values
11
8 không cho đúng thời điểm như được hiển thị trên PC của bạn.

Để tạo ra một thời gian phù hợp với những gì trên PC của bạn, hãy sử dụng

>>> import time
>>> x = 40000 
>>> time.strftime('%H:%M:%S', time.gmtime(x))
'11:06:40'                    # <- that's your desired output
>>> time.gmtime(x)
time.struct_time(tm_year=1970, tm_mon=1, tm_mday=1, tm_hour=11, tm_min=6, tm_sec=40, tm_wday=3, tm_yday=1, tm_isdst=0)
>>> time.gmtime(x).tm_hour    # <- that's how to access individual values
11
9 thay thế

Đã trả lời ngày 9 tháng 7 năm 2021 lúc 16:39Jul 9, 2021 at 16:39

Hướng dẫn convert int to time python - chuyển đổi int thành trăn thời gian

razor_chkrazor_chkrazor_chk

653 Huy hiệu bạc6 Huy hiệu Đồng3 silver badges6 bronze badges

1

Xem thảo luận

Cải thiện bài viết

Lưu bài viết

  • Đọc
  • Bàn luận
  • Xem thảo luận

    Cải thiện bài viết

    Lưu bài viết

    Đọc

    Bàn luận

    df['DataFrame Column'] = pd.to_datetime(df['DataFrame Column'], format=specify your format)

    Hãy để thảo luận về cách chuyển đổi một số nguyên thành DateTime trong đó. Bây giờ để chuyển đổi số nguyên thành DateTime trong Pandas DataFrame.

    Cú pháp của & nbsp; pd.to_datetime

    Tạo DataFrame để chuyển đổi số nguyên thành DateTime trong gấu trúc

    Kiểm tra kiểu dữ liệu cho cột ‘ngày là số nguyên.

    Python

    hello = datetime.time(hour, min, seconds)
    
    3
    hello = datetime.time(hour, min, seconds)
    
    4
    hello = datetime.time(hour, min, seconds)
    
    5
    hello = datetime.time(hour, min, seconds)
    
    6
    hello = datetime.time(hour.hour, min.minute, seconds.second)
    
    8
    hello = datetime.time(hour, min, seconds)
    
    8
    hello = datetime.time(hour.hour, min.minute, seconds.second)
    
    8
    hello = datetime.time(hour, min, seconds)
    
    6
    df['DataFrame Column'] = pd.to_datetime(df['DataFrame Column'], format=specify your format)
    1

    hello = datetime.time(hour, min, seconds)
    
    3
    df['DataFrame Column'] = pd.to_datetime(df['DataFrame Column'], format=specify your format)
    3

    hello = datetime.time(hour.hour, min.minute, seconds.second)
    
    0
    hello = datetime.time(hour.hour, min.minute, seconds.second)
    
    1

    format= '%Y%m%d'
    3
    format= '%Y%m%d'
    4

    format= '%Y%m%d'
    3
    format= '%Y%m%d'
    6

    Output:

    Hướng dẫn convert int to time python - chuyển đổi int thành trăn thời gian

    hello = datetime.time(hour.hour, min.minute, seconds.second) 2hello = datetime.time(hour.hour, min.minute, seconds.second) 3 hello = datetime.time(hour.hour, min.minute, seconds.second) 4hello = datetime.time(hour.hour, min.minute, seconds.second) 5hello = datetime.time(hour.hour, min.minute, seconds.second) 6hello = datetime.time(hour.hour, min.minute, seconds.second) 7hello = datetime.time(hour.hour, min.minute, seconds.second) 8hello = datetime.time(hour.hour, min.minute, seconds.second) 9hello = datetime.time(hour.hour, min.minute, seconds.second) 8hello = datetime.time(hour, min, seconds) 1hello = datetime.time(hour, min, seconds) 2

    df['DataFrame Column'] = pd.to_datetime(df['DataFrame Column'], format=specify your format)
    4
    hello = datetime.time(hour.hour, min.minute, seconds.second)
    
    3
    df['DataFrame Column'] = pd.to_datetime(df['DataFrame Column'], format=specify your format)
    6
    hello = datetime.time(hour.hour, min.minute, seconds.second)
    
    3
    df['DataFrame Column'] = pd.to_datetime(df['DataFrame Column'], format=specify your format)
    8
    hello = datetime.time(hour.hour, min.minute, seconds.second)
    
    5
    hello = datetime.time(hour.hour, min.minute, seconds.second)
    
    8
    hello = datetime.time(hour, min, seconds)
    
    4
    format= '%Y%m%d'
    2yyyymmdd, the date format can be represented as follows:

    format= '%Y%m%d'

    Python3

    Kiểm tra kiểu dữ liệu cho cột ‘ngày là số nguyên.

    Python

    hello = datetime.time(hour, min, seconds)
    
    3
    hello = datetime.time(hour, min, seconds)
    
    4
    hello = datetime.time(hour, min, seconds)
    
    5
    hello = datetime.time(hour, min, seconds)
    
    6
    hello = datetime.time(hour.hour, min.minute, seconds.second)
    
    8
    hello = datetime.time(hour, min, seconds)
    
    8
    hello = datetime.time(hour.hour, min.minute, seconds.second)
    
    8
    hello = datetime.time(hour, min, seconds)
    
    6
    df['DataFrame Column'] = pd.to_datetime(df['DataFrame Column'], format=specify your format)
    1

    hello = datetime.time(hour, min, seconds)
    
    3
    df['DataFrame Column'] = pd.to_datetime(df['DataFrame Column'], format=specify your format)
    3

    hello = datetime.time(hour.hour, min.minute, seconds.second)
    
    0
    hello = datetime.time(hour.hour, min.minute, seconds.second)
    
    1

    hello = datetime.time(hour.hour, min.minute, seconds.second)
    
    2
    hello = datetime.time(hour.hour, min.minute, seconds.second)
    
    3
    hello = datetime.time(hour.hour, min.minute, seconds.second)
    
    4
    hello = datetime.time(hour.hour, min.minute, seconds.second)
    
    5
    hello = datetime.time(hour.hour, min.minute, seconds.second)
    
    6
    hello = datetime.time(hour.hour, min.minute, seconds.second)
    
    7
    hello = datetime.time(hour.hour, min.minute, seconds.second)
    
    8
    hello = datetime.time(hour.hour, min.minute, seconds.second)
    
    9
    hello = datetime.time(hour.hour, min.minute, seconds.second)
    
    8
    hello = datetime.time(hour, min, seconds)
    
    1
    hello = datetime.time(hour, min, seconds)
    
    2

    format= '%Y%m%d'
    3
    format= '%Y%m%d'
    4

    format= '%Y%m%d'
    3
    format= '%Y%m%d'
    6

    Output::

    Hướng dẫn convert int to time python - chuyển đổi int thành trăn thời gian

    df['DataFrame Column'] = pd.to_datetime(df['DataFrame Column'], format=specify your format)4hello = datetime.time(hour.hour, min.minute, seconds.second) 3 df['DataFrame Column'] = pd.to_datetime(df['DataFrame Column'], format=specify your format)6hello = datetime.time(hour.hour, min.minute, seconds.second) 3df['DataFrame Column'] = pd.to_datetime(df['DataFrame Column'], format=specify your format)8hello = datetime.time(hour.hour, min.minute, seconds.second) 5hello = datetime.time(hour.hour, min.minute, seconds.second) 8hello = datetime.time(hour, min, seconds) 4format= '%Y%m%d'2

    Ví dụ 1:yymmdd. In this case, the date format would now contain ‘y’ in lowercase:

    format='%y%m%d'

    Python3

    Kiểm tra kiểu dữ liệu cho cột ‘ngày là số nguyên.

    Python

    hello = datetime.time(hour.hour, min.minute, seconds.second)
    
    0
    hello = datetime.time(hour.hour, min.minute, seconds.second)
    
    1

    hello = datetime.time(hour, min, seconds)
    
    3
    df['DataFrame Column'] = pd.to_datetime(df['DataFrame Column'], format=specify your format)
    3

    hello = datetime.time(hour.hour, min.minute, seconds.second)
    
    0
    hello = datetime.time(hour.hour, min.minute, seconds.second)
    
    1

    hello = datetime.time(hour.hour, min.minute, seconds.second)
    
    2
    hello = datetime.time(hour.hour, min.minute, seconds.second)
    
    3
    hello = datetime.time(hour.hour, min.minute, seconds.second)
    
    4
    hello = datetime.time(hour.hour, min.minute, seconds.second)
    
    5
    hello = datetime.time(hour.hour, min.minute, seconds.second)
    
    6
    hello = datetime.time(hour.hour, min.minute, seconds.second)
    
    7
    hello = datetime.time(hour.hour, min.minute, seconds.second)
    
    8
    hello = datetime.time(hour.hour, min.minute, seconds.second)
    
    9
    hello = datetime.time(hour.hour, min.minute, seconds.second)
    
    8
    hello = datetime.time(hour, min, seconds)
    
    1
    hello = datetime.time(hour, min, seconds)
    
    2

    format= '%Y%m%d'
    3
    format= '%Y%m%d'
    4

    format= '%Y%m%d'
    3
    format= '%Y%m%d'
    6

    Output:

    Hướng dẫn convert int to time python - chuyển đổi int thành trăn thời gian

    df['DataFrame Column'] = pd.to_datetime(df['DataFrame Column'], format=specify your format)4hello = datetime.time(hour.hour, min.minute, seconds.second) 3 df['DataFrame Column'] = pd.to_datetime(df['DataFrame Column'], format=specify your format)6hello = datetime.time(hour.hour, min.minute, seconds.second) 3df['DataFrame Column'] = pd.to_datetime(df['DataFrame Column'], format=specify your format)8hello = datetime.time(hour.hour, min.minute, seconds.second) 5hello = datetime.time(hour.hour, min.minute, seconds.second) 8hello = datetime.time(hour, min, seconds) 4format= '%Y%m%d'2

    Ví dụ 1:

    format='%Y%m%d%H%M%S'

    Python3

    Kiểm tra kiểu dữ liệu cho cột ‘ngày là số nguyên.

    Python

    hello = datetime.time(hour, min, seconds)
    
    3
    hello = datetime.time(hour, min, seconds)
    
    4
    hello = datetime.time(hour, min, seconds)
    
    5
    hello = datetime.time(hour, min, seconds)
    
    6
    hello = datetime.time(hour.hour, min.minute, seconds.second)
    
    8
    hello = datetime.time(hour, min, seconds)
    
    8
    hello = datetime.time(hour.hour, min.minute, seconds.second)
    
    8
    hello = datetime.time(hour, min, seconds)
    
    6
    df['DataFrame Column'] = pd.to_datetime(df['DataFrame Column'], format=specify your format)
    1

    hello = datetime.time(hour, min, seconds)
    
    3
    df['DataFrame Column'] = pd.to_datetime(df['DataFrame Column'], format=specify your format)
    3

    hello = datetime.time(hour.hour, min.minute, seconds.second)
    
    0
    hello = datetime.time(hour.hour, min.minute, seconds.second)
    
    1

    hello = datetime.time(hour.hour, min.minute, seconds.second)
    
    2
    hello = datetime.time(hour.hour, min.minute, seconds.second)
    
    3
    hello = datetime.time(hour.hour, min.minute, seconds.second)
    
    4
    hello = datetime.time(hour.hour, min.minute, seconds.second)
    
    5
    hello = datetime.time(hour.hour, min.minute, seconds.second)
    
    6
    hello = datetime.time(hour.hour, min.minute, seconds.second)
    
    7
    hello = datetime.time(hour.hour, min.minute, seconds.second)
    
    8
    hello = datetime.time(hour.hour, min.minute, seconds.second)
    
    9
    hello = datetime.time(hour.hour, min.minute, seconds.second)
    
    8
    hello = datetime.time(hour, min, seconds)
    
    1
    hello = datetime.time(hour, min, seconds)
    
    2

    format= '%Y%m%d'
    3
    format= '%Y%m%d'
    4

    format= '%Y%m%d'
    3
    format= '%Y%m%d'
    6

    Output:

    Hướng dẫn convert int to time python - chuyển đổi int thành trăn thời gian

    df['DataFrame Column'] = pd.to_datetime(df['DataFrame Column'], format=specify your format)4hello = datetime.time(hour.hour, min.minute, seconds.second) 3 df['DataFrame Column'] = pd.to_datetime(df['DataFrame Column'], format=specify your format)6hello = datetime.time(hour.hour, min.minute, seconds.second) 3df['DataFrame Column'] = pd.to_datetime(df['DataFrame Column'], format=specify your format)8hello = datetime.time(hour.hour, min.minute, seconds.second) 5hello = datetime.time(hour.hour, min.minute, seconds.second) 8hello = datetime.time(hour, min, seconds) 4format= '%Y%m%d'2

    Ví dụ 1:

    format='%Y%m%d%H%M%S%F'

    Python3

    Kiểm tra kiểu dữ liệu cho cột ‘ngày là số nguyên.

    Python

    hello = datetime.time(hour.hour, min.minute, seconds.second)
    
    12
    hello = datetime.time(hour.hour, min.minute, seconds.second)
    
    13
    hello = datetime.time(hour, min, seconds)
    
    2

    hello = datetime.time(hour, min, seconds)
    
    3
    hello = datetime.time(hour, min, seconds)
    
    4
    hello = datetime.time(hour, min, seconds)
    
    5
    hello = datetime.time(hour, min, seconds)
    
    6
    hello = datetime.time(hour.hour, min.minute, seconds.second)
    
    8
    hello = datetime.time(hour, min, seconds)
    
    8
    hello = datetime.time(hour.hour, min.minute, seconds.second)
    
    8
    hello = datetime.time(hour, min, seconds)
    
    6
    df['DataFrame Column'] = pd.to_datetime(df['DataFrame Column'], format=specify your format)
    1

    hello = datetime.time(hour, min, seconds)
    
    3
    df['DataFrame Column'] = pd.to_datetime(df['DataFrame Column'], format=specify your format)
    3

    hello = datetime.time(hour.hour, min.minute, seconds.second)
    
    0
    hello = datetime.time(hour.hour, min.minute, seconds.second)
    
    1

    hello = datetime.time(hour.hour, min.minute, seconds.second)
    
    2
    hello = datetime.time(hour.hour, min.minute, seconds.second)
    
    3
    hello = datetime.time(hour.hour, min.minute, seconds.second)
    
    4
    hello = datetime.time(hour.hour, min.minute, seconds.second)
    
    5
    hello = datetime.time(hour.hour, min.minute, seconds.second)
    
    6
    hello = datetime.time(hour.hour, min.minute, seconds.second)
    
    7
    hello = datetime.time(hour.hour, min.minute, seconds.second)
    
    8
    hello = datetime.time(hour.hour, min.minute, seconds.second)
    
    9
    hello = datetime.time(hour.hour, min.minute, seconds.second)
    
    8
    hello = datetime.time(hour, min, seconds)
    
    1
    hello = datetime.time(hour, min, seconds)
    
    2

    format= '%Y%m%d'
    3
    format= '%Y%m%d'
    4

    format= '%Y%m%d'
    3
    format= '%Y%m%d'
    6

    Output:

    Hướng dẫn convert int to time python - chuyển đổi int thành trăn thời gian


    Làm thế nào để bạn chuyển đổi int theo thời gian trong Python?

    Chuyển đổi số nguyên thành DateTime trong Python..
    >>> Nhập Datetime ..
    >>> your_timestamp = 1331856000000 ..
    >>> Ngày = DateTime.ngày giờ.từ Tối đa (your_timestamp / 1e3).
    >>> Ngày ..
    ngày giờ.DateTime (2012, 3, 16, 1, 0).

    Làm thế nào để bạn chuyển đổi int sang thời gian?

    Để chuyển đổi số int trong vài phút theo thời gian trong mysql, bạn có thể sử dụng hàm sec_to_time ().Chèn một số bản ghi trong bảng bằng lệnh chèn.use SEC_TO_TIME() function. Insert some records in the table using insert command.

    Làm thế nào để bạn chuyển đổi một số 4 chữ số theo thời gian trong Python?

    Bạn cần sử dụng PD.TO_DATETIME bằng cách chuyển loạt df.st_time cho nó.Khi bạn làm, bạn có thể truy cập thành phần thời gian.use pd. to_datetime by passing the series df. st_time to it. Once you do, you can access the time component.

    Làm thế nào để bạn chuyển đổi int sang ngày trong Python?

    Khoa học dữ liệu thực tế bằng cách sử dụng Python, bạn có thể sử dụng hàm Fromtimestamp từ mô -đun DateTime để nhận ngày từ dấu thời gian UNIX.Hàm này lấy dấu thời gian làm đầu vào và trả về đối tượng DateTime tương ứng với dấu thời gian.use the fromtimestamp function from the datetime module to get a date from a UNIX timestamp. This function takes the timestamp as input and returns the datetime object corresponding to the timestamp.