Hướng dẫn python get current time in specific timezone - python lấy thời gian hiện tại trong múi giờ cụ thể

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
    In order to get the current time of different time zones, we will be using the pytz python library.

    Bàn luận

    Timezone được định nghĩa là một khu vực hoặc khu vực địa lý trong suốt thời gian tiêu chuẩn được quan sát. Về cơ bản nó đề cập đến thời gian địa phương của một khu vực hoặc quốc gia. Hầu hết các múi giờ được bù đắp từ thời gian phối hợp (UTC), tiêu chuẩn thế giới đối với múi giờ. Trong đơn đặt hàng để có thời gian hiện tại của các múi giờ khác nhau, chúng tôi sẽ sử dụng thư viện pytz Python.

    • Làm thế nào để có được thời gian hiện tại? – it helps to get the current local time
    • Để có được thời gian địa phương, chúng ta có thể sử dụng mô -đun thời gian. Một số chức năng quan trọng của mô -đun thời gian – it helps to decide the format of the time to be used to display the time

    localtime () - nó giúp có được thời gian địa phương hiện tại

    Strftime (Hồi%H H:%M:%S, t) - Nó giúp quyết định định dạng thời gian được sử dụng để hiển thị thời gian

    • Làm thế nào để có được thời gian hiện tại trong các khu vực khác nhau? – it helps to get the standard UTC time zone
    • Để có được thời gian hiện tại của một múi giờ cụ thể, cần phải sử dụng thư viện Python pytz. Một số lệnh quan trọng của thư viện PYTZ là – it helps to get the time zone of a particular location
    • UTC - Nó giúp có được múi giờ UTC tiêu chuẩn – it helps to get the date, time, utc standard in default format
    • timezone () - nó giúp có được múi giờ của một địa điểm cụ thể – it helps to convert the time of a particular time zone into another time zone

    Examples:

    Bây giờ () - nó giúp có được ngày, thời gian, tiêu chuẩn UTC ở định dạng mặc định

    astimezone () - Nó giúp chuyển đổi thời gian của một múi giờ cụ thể thành múi giờ khác

    import time

    Output:
    UTC in Default Format :  2020-03-31 07:15:59.640418+00:00
    IST in Default Format :  2020-03-31 12:45:59.692642+05:30
    Date & Time in UTC :  2020:03:31 07:15:59 UTC+0000
    Date & Time in IST :  2020:03:31 12:45:59 IST+0530
    
    5
    Output:
    UTC in Default Format :  2020-03-31 07:15:59.640418+00:00
    IST in Default Format :  2020-03-31 12:45:59.692642+05:30
    Date & Time in UTC :  2020:03:31 07:15:59 UTC+0000
    Date & Time in IST :  2020:03:31 12:45:59 IST+0530
    
    6

    Output:

    11:58:19
    

    curr_time = time.localtime()
    Examples:

    Chúng tôi sẽ có thời gian hiện tại địa phương của khu vực và các máy tính thời gian UTC tiêu chuẩn:

    Output:
    UTC in Default Format :  2020-03-31 07:15:59.640418+00:00
    IST in Default Format :  2020-03-31 12:45:59.692642+05:30
    Date & Time in UTC :  2020:03:31 07:15:59 UTC+0000
    Date & Time in IST :  2020:03:31 12:45:59 IST+0530
    
    7
    Output:
    UTC in Default Format :  2020-03-31 07:15:59.640418+00:00
    IST in Default Format :  2020-03-31 12:45:59.692642+05:30
    Date & Time in UTC :  2020:03:31 07:15:59 UTC+0000
    Date & Time in IST :  2020:03:31 12:45:59 IST+0530
    
    8import
    Output:
    UTC Format               IST Format
    2020-03-31 11:21:13 UTC +0000       2020-03-31 16:51:13 IST +0530
    2020-03-31 11:21:13 UTC +0000       2020-03-31 16:51:13 IST +0530
    2020-03-31 11:21:13 UTC +0000       2020-03-31 16:51:13 IST +0530
    2020-03-31 11:21:13 UTC +0000       2020-03-31 16:51:13 IST +0530
    2020-03-31 11:21:13 UTC +0000       2020-03-31 16:51:13 IST +0530
    
    0

    import pytz

    Output:
    UTC in Default Format :  2020-03-31 07:15:59.640418+00:00
    IST in Default Format :  2020-03-31 12:45:59.692642+05:30
    Date & Time in UTC :  2020:03:31 07:15:59 UTC+0000
    Date & Time in IST :  2020:03:31 12:45:59 IST+0530
    
    5pytz2pytz3pytz4

    pytz5pytz6

    Output:
    UTC in Default Format :  2020-03-31 07:15:59.640418+00:00
    IST in Default Format :  2020-03-31 12:45:59.692642+05:30
    Date & Time in UTC :  2020:03:31 07:15:59 UTC+0000
    Date & Time in IST :  2020:03:31 12:45:59 IST+0530
    
    5pytz2pytz9pytz4

    pytz5pytz2

    Output:
    UTC Format               IST Format
    2020-03-31 11:21:13 UTC +0000       2020-03-31 16:51:13 IST +0530
    2020-03-31 11:21:13 UTC +0000       2020-03-31 16:51:13 IST +0530
    2020-03-31 11:21:13 UTC +0000       2020-03-31 16:51:13 IST +0530
    2020-03-31 11:21:13 UTC +0000       2020-03-31 16:51:13 IST +0530
    2020-03-31 11:21:13 UTC +0000       2020-03-31 16:51:13 IST +0530
    
    3=
    Output:
    UTC Format               IST Format
    2020-03-31 11:21:13 UTC +0000       2020-03-31 16:51:13 IST +0530
    2020-03-31 11:21:13 UTC +0000       2020-03-31 16:51:13 IST +0530
    2020-03-31 11:21:13 UTC +0000       2020-03-31 16:51:13 IST +0530
    2020-03-31 11:21:13 UTC +0000       2020-03-31 16:51:13 IST +0530
    2020-03-31 11:21:13 UTC +0000       2020-03-31 16:51:13 IST +0530
    
    5

    Output:
    UTC in Default Format :  2020-03-31 07:15:59.640418+00:00
    IST in Default Format :  2020-03-31 12:45:59.692642+05:30
    Date & Time in UTC :  2020:03:31 07:15:59 UTC+0000
    Date & Time in IST :  2020:03:31 12:45:59 IST+0530
    
    5pytz2pytz8pytz9

    pytz5import1import2import3

    Output:
    UTC Format               IST Format
    2020-03-31 11:21:13 UTC +0000       2020-03-31 16:51:13 IST +0530
    2020-03-31 11:21:13 UTC +0000       2020-03-31 16:51:13 IST +0530
    2020-03-31 11:21:13 UTC +0000       2020-03-31 16:51:13 IST +0530
    2020-03-31 11:21:13 UTC +0000       2020-03-31 16:51:13 IST +0530
    2020-03-31 11:21:13 UTC +0000       2020-03-31 16:51:13 IST +0530
    
    6=
    Output:
    UTC Format               IST Format
    2020-03-31 11:21:13 UTC +0000       2020-03-31 16:51:13 IST +0530
    2020-03-31 11:21:13 UTC +0000       2020-03-31 16:51:13 IST +0530
    2020-03-31 11:21:13 UTC +0000       2020-03-31 16:51:13 IST +0530
    2020-03-31 11:21:13 UTC +0000       2020-03-31 16:51:13 IST +0530
    2020-03-31 11:21:13 UTC +0000       2020-03-31 16:51:13 IST +0530
    
    8
    Output:
    UTC Format               IST Format
    2020-03-31 11:21:13 UTC +0000       2020-03-31 16:51:13 IST +0530
    2020-03-31 11:21:13 UTC +0000       2020-03-31 16:51:13 IST +0530
    2020-03-31 11:21:13 UTC +0000       2020-03-31 16:51:13 IST +0530
    2020-03-31 11:21:13 UTC +0000       2020-03-31 16:51:13 IST +0530
    2020-03-31 11:21:13 UTC +0000       2020-03-31 16:51:13 IST +0530
    
    9pytz0

    pytz3= pytz5

    pytz5time2import2import3

    Output:
    UTC in Default Format :  2020-03-31 07:15:59.640418+00:00
    IST in Default Format :  2020-03-31 12:45:59.692642+05:30
    Date & Time in UTC :  2020:03:31 07:15:59 UTC+0000
    Date & Time in IST :  2020:03:31 12:45:59 IST+0530
    

    import4= import6
    Examples:

    Chúng tôi sẽ có thời gian hiện tại địa phương của khu vực và các máy tính thời gian UTC tiêu chuẩn:

    Output:
    UTC in Default Format :  2020-03-31 07:15:59.640418+00:00
    IST in Default Format :  2020-03-31 12:45:59.692642+05:30
    Date & Time in UTC :  2020:03:31 07:15:59 UTC+0000
    Date & Time in IST :  2020:03:31 12:45:59 IST+0530
    
    7
    Output:
    UTC in Default Format :  2020-03-31 07:15:59.640418+00:00
    IST in Default Format :  2020-03-31 12:45:59.692642+05:30
    Date & Time in UTC :  2020:03:31 07:15:59 UTC+0000
    Date & Time in IST :  2020:03:31 12:45:59 IST+0530
    
    8import
    Output:
    UTC Format               IST Format
    2020-03-31 11:21:13 UTC +0000       2020-03-31 16:51:13 IST +0530
    2020-03-31 11:21:13 UTC +0000       2020-03-31 16:51:13 IST +0530
    2020-03-31 11:21:13 UTC +0000       2020-03-31 16:51:13 IST +0530
    2020-03-31 11:21:13 UTC +0000       2020-03-31 16:51:13 IST +0530
    2020-03-31 11:21:13 UTC +0000       2020-03-31 16:51:13 IST +0530
    
    0

    import pytz

    Output:
    UTC Format               IST Format
    2020-03-31 11:21:13 UTC +0000       2020-03-31 16:51:13 IST +0530
    2020-03-31 11:21:13 UTC +0000       2020-03-31 16:51:13 IST +0530
    2020-03-31 11:21:13 UTC +0000       2020-03-31 16:51:13 IST +0530
    2020-03-31 11:21:13 UTC +0000       2020-03-31 16:51:13 IST +0530
    2020-03-31 11:21:13 UTC +0000       2020-03-31 16:51:13 IST +0530
    
    3=
    Output:
    UTC Format               IST Format
    2020-03-31 11:21:13 UTC +0000       2020-03-31 16:51:13 IST +0530
    2020-03-31 11:21:13 UTC +0000       2020-03-31 16:51:13 IST +0530
    2020-03-31 11:21:13 UTC +0000       2020-03-31 16:51:13 IST +0530
    2020-03-31 11:21:13 UTC +0000       2020-03-31 16:51:13 IST +0530
    2020-03-31 11:21:13 UTC +0000       2020-03-31 16:51:13 IST +0530
    
    5

    Output:
    UTC Format               IST Format
    2020-03-31 11:21:13 UTC +0000       2020-03-31 16:51:13 IST +0530
    2020-03-31 11:21:13 UTC +0000       2020-03-31 16:51:13 IST +0530
    2020-03-31 11:21:13 UTC +0000       2020-03-31 16:51:13 IST +0530
    2020-03-31 11:21:13 UTC +0000       2020-03-31 16:51:13 IST +0530
    2020-03-31 11:21:13 UTC +0000       2020-03-31 16:51:13 IST +0530
    
    6=
    Output:
    UTC Format               IST Format
    2020-03-31 11:21:13 UTC +0000       2020-03-31 16:51:13 IST +0530
    2020-03-31 11:21:13 UTC +0000       2020-03-31 16:51:13 IST +0530
    2020-03-31 11:21:13 UTC +0000       2020-03-31 16:51:13 IST +0530
    2020-03-31 11:21:13 UTC +0000       2020-03-31 16:51:13 IST +0530
    2020-03-31 11:21:13 UTC +0000       2020-03-31 16:51:13 IST +0530
    
    8
    Output:
    UTC Format               IST Format
    2020-03-31 11:21:13 UTC +0000       2020-03-31 16:51:13 IST +0530
    2020-03-31 11:21:13 UTC +0000       2020-03-31 16:51:13 IST +0530
    2020-03-31 11:21:13 UTC +0000       2020-03-31 16:51:13 IST +0530
    2020-03-31 11:21:13 UTC +0000       2020-03-31 16:51:13 IST +0530
    2020-03-31 11:21:13 UTC +0000       2020-03-31 16:51:13 IST +0530
    
    9pytz0

    pytz3= pytz5

    import4= import6

    Output:
    UTC in Default Format :  2020-03-31 07:15:59.640418+00:00
    IST in Default Format :  2020-03-31 12:45:59.692642+05:30
    Date & Time in UTC :  2020:03:31 07:15:59 UTC+0000
    Date & Time in IST :  2020:03:31 12:45:59 IST+0530
    
    5pytz2import9pytz4

    So sánh định dạng UTC và IST của các múi giờ của các khu vực khác nhau:

    curr_time 4=

    Output:
    UTC Format               IST Format
    2020-03-31 11:21:13 UTC +0000       2020-03-31 16:51:13 IST +0530
    2020-03-31 11:21:13 UTC +0000       2020-03-31 16:51:13 IST +0530
    2020-03-31 11:21:13 UTC +0000       2020-03-31 16:51:13 IST +0530
    2020-03-31 11:21:13 UTC +0000       2020-03-31 16:51:13 IST +0530
    2020-03-31 11:21:13 UTC +0000       2020-03-31 16:51:13 IST +0530
    
    8
    Output:
    UTC Format               IST Format
    2020-03-31 11:21:13 UTC +0000       2020-03-31 16:51:13 IST +0530
    2020-03-31 11:21:13 UTC +0000       2020-03-31 16:51:13 IST +0530
    2020-03-31 11:21:13 UTC +0000       2020-03-31 16:51:13 IST +0530
    2020-03-31 11:21:13 UTC +0000       2020-03-31 16:51:13 IST +0530
    2020-03-31 11:21:13 UTC +0000       2020-03-31 16:51:13 IST +0530
    
    9curr_time 8

    curr_time 9=

    Output:
    UTC Format               IST Format
    2020-03-31 11:21:13 UTC +0000       2020-03-31 16:51:13 IST +0530
    2020-03-31 11:21:13 UTC +0000       2020-03-31 16:51:13 IST +0530
    2020-03-31 11:21:13 UTC +0000       2020-03-31 16:51:13 IST +0530
    2020-03-31 11:21:13 UTC +0000       2020-03-31 16:51:13 IST +0530
    2020-03-31 11:21:13 UTC +0000       2020-03-31 16:51:13 IST +0530
    
    8=2pytz0

    =4=

    Output:
    UTC Format               IST Format
    2020-03-31 11:21:13 UTC +0000       2020-03-31 16:51:13 IST +0530
    2020-03-31 11:21:13 UTC +0000       2020-03-31 16:51:13 IST +0530
    2020-03-31 11:21:13 UTC +0000       2020-03-31 16:51:13 IST +0530
    2020-03-31 11:21:13 UTC +0000       2020-03-31 16:51:13 IST +0530
    2020-03-31 11:21:13 UTC +0000       2020-03-31 16:51:13 IST +0530
    
    8=7pytz0

    =9=

    Output:
    UTC Format               IST Format
    2020-03-31 11:21:13 UTC +0000       2020-03-31 16:51:13 IST +0530
    2020-03-31 11:21:13 UTC +0000       2020-03-31 16:51:13 IST +0530
    2020-03-31 11:21:13 UTC +0000       2020-03-31 16:51:13 IST +0530
    2020-03-31 11:21:13 UTC +0000       2020-03-31 16:51:13 IST +0530
    2020-03-31 11:21:13 UTC +0000       2020-03-31 16:51:13 IST +0530
    
    8time.localtime()2pytz0

    time.localtime()4=

    Output:
    UTC Format               IST Format
    2020-03-31 11:21:13 UTC +0000       2020-03-31 16:51:13 IST +0530
    2020-03-31 11:21:13 UTC +0000       2020-03-31 16:51:13 IST +0530
    2020-03-31 11:21:13 UTC +0000       2020-03-31 16:51:13 IST +0530
    2020-03-31 11:21:13 UTC +0000       2020-03-31 16:51:13 IST +0530
    2020-03-31 11:21:13 UTC +0000       2020-03-31 16:51:13 IST +0530
    
    8time.localtime()7pytz0

    time.localtime()9=

    Output:
    UTC in Default Format :  2020-03-31 07:15:59.640418+00:00
    IST in Default Format :  2020-03-31 12:45:59.692642+05:30
    Date & Time in UTC :  2020:03:31 07:15:59 UTC+0000
    Date & Time in IST :  2020:03:31 12:45:59 IST+0530
    
    01

    Output:
    UTC in Default Format :  2020-03-31 07:15:59.640418+00:00
    IST in Default Format :  2020-03-31 12:45:59.692642+05:30
    Date & Time in UTC :  2020:03:31 07:15:59 UTC+0000
    Date & Time in IST :  2020:03:31 12:45:59 IST+0530
    
    02=
    Output:
    UTC in Default Format :  2020-03-31 07:15:59.640418+00:00
    IST in Default Format :  2020-03-31 12:45:59.692642+05:30
    Date & Time in UTC :  2020:03:31 07:15:59 UTC+0000
    Date & Time in IST :  2020:03:31 12:45:59 IST+0530
    
    04

    Output:
    UTC in Default Format :  2020-03-31 07:15:59.640418+00:00
    IST in Default Format :  2020-03-31 12:45:59.692642+05:30
    Date & Time in UTC :  2020:03:31 07:15:59 UTC+0000
    Date & Time in IST :  2020:03:31 12:45:59 IST+0530
    
    05=
    Output:
    UTC in Default Format :  2020-03-31 07:15:59.640418+00:00
    IST in Default Format :  2020-03-31 12:45:59.692642+05:30
    Date & Time in UTC :  2020:03:31 07:15:59 UTC+0000
    Date & Time in IST :  2020:03:31 12:45:59 IST+0530
    
    07

    Output:
    UTC in Default Format :  2020-03-31 07:15:59.640418+00:00
    IST in Default Format :  2020-03-31 12:45:59.692642+05:30
    Date & Time in UTC :  2020:03:31 07:15:59 UTC+0000
    Date & Time in IST :  2020:03:31 12:45:59 IST+0530
    
    5pytz2
    Output:
    UTC in Default Format :  2020-03-31 07:15:59.640418+00:00
    IST in Default Format :  2020-03-31 12:45:59.692642+05:30
    Date & Time in UTC :  2020:03:31 07:15:59 UTC+0000
    Date & Time in IST :  2020:03:31 12:45:59 IST+0530
    
    31pytz0

    Output:
    UTC in Default Format :  2020-03-31 07:15:59.640418+00:00
    IST in Default Format :  2020-03-31 12:45:59.692642+05:30
    Date & Time in UTC :  2020:03:31 07:15:59 UTC+0000
    Date & Time in IST :  2020:03:31 12:45:59 IST+0530
    
    5
    Output:
    UTC in Default Format :  2020-03-31 07:15:59.640418+00:00
    IST in Default Format :  2020-03-31 12:45:59.692642+05:30
    Date & Time in UTC :  2020:03:31 07:15:59 UTC+0000
    Date & Time in IST :  2020:03:31 12:45:59 IST+0530
    
    34
    Output:
    UTC in Default Format :  2020-03-31 07:15:59.640418+00:00
    IST in Default Format :  2020-03-31 12:45:59.692642+05:30
    Date & Time in UTC :  2020:03:31 07:15:59 UTC+0000
    Date & Time in IST :  2020:03:31 12:45:59 IST+0530
    
    35
    Output:
    UTC in Default Format :  2020-03-31 07:15:59.640418+00:00
    IST in Default Format :  2020-03-31 12:45:59.692642+05:30
    Date & Time in UTC :  2020:03:31 07:15:59 UTC+0000
    Date & Time in IST :  2020:03:31 12:45:59 IST+0530
    
    36

    pytz5

    Output:
    UTC in Default Format :  2020-03-31 07:15:59.640418+00:00
    IST in Default Format :  2020-03-31 12:45:59.692642+05:30
    Date & Time in UTC :  2020:03:31 07:15:59 UTC+0000
    Date & Time in IST :  2020:03:31 12:45:59 IST+0530
    
    38pytz9

    Output:
    UTC in Default Format :  2020-03-31 07:15:59.640418+00:00
    IST in Default Format :  2020-03-31 12:45:59.692642+05:30
    Date & Time in UTC :  2020:03:31 07:15:59 UTC+0000
    Date & Time in IST :  2020:03:31 12:45:59 IST+0530
    
    08=
    Output:
    UTC in Default Format :  2020-03-31 07:15:59.640418+00:00
    IST in Default Format :  2020-03-31 12:45:59.692642+05:30
    Date & Time in UTC :  2020:03:31 07:15:59 UTC+0000
    Date & Time in IST :  2020:03:31 12:45:59 IST+0530
    
    10

    Output:
    UTC in Default Format :  2020-03-31 07:15:59.640418+00:00
    IST in Default Format :  2020-03-31 12:45:59.692642+05:30
    Date & Time in UTC :  2020:03:31 07:15:59 UTC+0000
    Date & Time in IST :  2020:03:31 12:45:59 IST+0530
    
    5
    Output:
    UTC in Default Format :  2020-03-31 07:15:59.640418+00:00
    IST in Default Format :  2020-03-31 12:45:59.692642+05:30
    Date & Time in UTC :  2020:03:31 07:15:59 UTC+0000
    Date & Time in IST :  2020:03:31 12:45:59 IST+0530
    
    45
    Output:
    UTC in Default Format :  2020-03-31 07:15:59.640418+00:00
    IST in Default Format :  2020-03-31 12:45:59.692642+05:30
    Date & Time in UTC :  2020:03:31 07:15:59 UTC+0000
    Date & Time in IST :  2020:03:31 12:45:59 IST+0530
    
    35
    Output:
    UTC in Default Format :  2020-03-31 07:15:59.640418+00:00
    IST in Default Format :  2020-03-31 12:45:59.692642+05:30
    Date & Time in UTC :  2020:03:31 07:15:59 UTC+0000
    Date & Time in IST :  2020:03:31 12:45:59 IST+0530
    
    36

    pytz5

    Output:
    UTC in Default Format :  2020-03-31 07:15:59.640418+00:00
    IST in Default Format :  2020-03-31 12:45:59.692642+05:30
    Date & Time in UTC :  2020:03:31 07:15:59 UTC+0000
    Date & Time in IST :  2020:03:31 12:45:59 IST+0530
    
    38pytz9

    pytz5

    Output:
    UTC in Default Format :  2020-03-31 07:15:59.640418+00:00
    IST in Default Format :  2020-03-31 12:45:59.692642+05:30
    Date & Time in UTC :  2020:03:31 07:15:59 UTC+0000
    Date & Time in IST :  2020:03:31 12:45:59 IST+0530
    
    41
    Output:
    UTC in Default Format :  2020-03-31 07:15:59.640418+00:00
    IST in Default Format :  2020-03-31 12:45:59.692642+05:30
    Date & Time in UTC :  2020:03:31 07:15:59 UTC+0000
    Date & Time in IST :  2020:03:31 12:45:59 IST+0530
    
    35import3

    Output:
    UTC in Default Format :  2020-03-31 07:15:59.640418+00:00
    IST in Default Format :  2020-03-31 12:45:59.692642+05:30
    Date & Time in UTC :  2020:03:31 07:15:59 UTC+0000
    Date & Time in IST :  2020:03:31 12:45:59 IST+0530
    
    5
    Output:
    UTC in Default Format :  2020-03-31 07:15:59.640418+00:00
    IST in Default Format :  2020-03-31 12:45:59.692642+05:30
    Date & Time in UTC :  2020:03:31 07:15:59 UTC+0000
    Date & Time in IST :  2020:03:31 12:45:59 IST+0530
    
    56
    Output:
    UTC in Default Format :  2020-03-31 07:15:59.640418+00:00
    IST in Default Format :  2020-03-31 12:45:59.692642+05:30
    Date & Time in UTC :  2020:03:31 07:15:59 UTC+0000
    Date & Time in IST :  2020:03:31 12:45:59 IST+0530
    
    35
    Output:
    UTC in Default Format :  2020-03-31 07:15:59.640418+00:00
    IST in Default Format :  2020-03-31 12:45:59.692642+05:30
    Date & Time in UTC :  2020:03:31 07:15:59 UTC+0000
    Date & Time in IST :  2020:03:31 12:45:59 IST+0530
    
    36

    pytz5

    Output:
    UTC in Default Format :  2020-03-31 07:15:59.640418+00:00
    IST in Default Format :  2020-03-31 12:45:59.692642+05:30
    Date & Time in UTC :  2020:03:31 07:15:59 UTC+0000
    Date & Time in IST :  2020:03:31 12:45:59 IST+0530
    
    38pytz9

    pytz5

    Output:
    UTC in Default Format :  2020-03-31 07:15:59.640418+00:00
    IST in Default Format :  2020-03-31 12:45:59.692642+05:30
    Date & Time in UTC :  2020:03:31 07:15:59 UTC+0000
    Date & Time in IST :  2020:03:31 12:45:59 IST+0530
    
    41
    Output:
    UTC in Default Format :  2020-03-31 07:15:59.640418+00:00
    IST in Default Format :  2020-03-31 12:45:59.692642+05:30
    Date & Time in UTC :  2020:03:31 07:15:59 UTC+0000
    Date & Time in IST :  2020:03:31 12:45:59 IST+0530
    
    35import3

    Output:
    UTC in Default Format :  2020-03-31 07:15:59.640418+00:00
    IST in Default Format :  2020-03-31 12:45:59.692642+05:30
    Date & Time in UTC :  2020:03:31 07:15:59 UTC+0000
    Date & Time in IST :  2020:03:31 12:45:59 IST+0530
    
    5
    Output:
    UTC in Default Format :  2020-03-31 07:15:59.640418+00:00
    IST in Default Format :  2020-03-31 12:45:59.692642+05:30
    Date & Time in UTC :  2020:03:31 07:15:59 UTC+0000
    Date & Time in IST :  2020:03:31 12:45:59 IST+0530
    
    67
    Output:
    UTC in Default Format :  2020-03-31 07:15:59.640418+00:00
    IST in Default Format :  2020-03-31 12:45:59.692642+05:30
    Date & Time in UTC :  2020:03:31 07:15:59 UTC+0000
    Date & Time in IST :  2020:03:31 12:45:59 IST+0530
    
    35
    Output:
    UTC in Default Format :  2020-03-31 07:15:59.640418+00:00
    IST in Default Format :  2020-03-31 12:45:59.692642+05:30
    Date & Time in UTC :  2020:03:31 07:15:59 UTC+0000
    Date & Time in IST :  2020:03:31 12:45:59 IST+0530
    
    36

    pytz5

    Output:
    UTC in Default Format :  2020-03-31 07:15:59.640418+00:00
    IST in Default Format :  2020-03-31 12:45:59.692642+05:30
    Date & Time in UTC :  2020:03:31 07:15:59 UTC+0000
    Date & Time in IST :  2020:03:31 12:45:59 IST+0530
    
    38pytz9

    pytz5

    Output:
    UTC in Default Format :  2020-03-31 07:15:59.640418+00:00
    IST in Default Format :  2020-03-31 12:45:59.692642+05:30
    Date & Time in UTC :  2020:03:31 07:15:59 UTC+0000
    Date & Time in IST :  2020:03:31 12:45:59 IST+0530
    
    41
    Output:
    UTC in Default Format :  2020-03-31 07:15:59.640418+00:00
    IST in Default Format :  2020-03-31 12:45:59.692642+05:30
    Date & Time in UTC :  2020:03:31 07:15:59 UTC+0000
    Date & Time in IST :  2020:03:31 12:45:59 IST+0530
    
    35import3

    Output:
    UTC in Default Format :  2020-03-31 07:15:59.640418+00:00
    IST in Default Format :  2020-03-31 12:45:59.692642+05:30
    Date & Time in UTC :  2020:03:31 07:15:59 UTC+0000
    Date & Time in IST :  2020:03:31 12:45:59 IST+0530
    
    5
    Output:
    UTC in Default Format :  2020-03-31 07:15:59.640418+00:00
    IST in Default Format :  2020-03-31 12:45:59.692642+05:30
    Date & Time in UTC :  2020:03:31 07:15:59 UTC+0000
    Date & Time in IST :  2020:03:31 12:45:59 IST+0530
    
    78
    Output:
    UTC in Default Format :  2020-03-31 07:15:59.640418+00:00
    IST in Default Format :  2020-03-31 12:45:59.692642+05:30
    Date & Time in UTC :  2020:03:31 07:15:59 UTC+0000
    Date & Time in IST :  2020:03:31 12:45:59 IST+0530
    
    35
    Output:
    UTC in Default Format :  2020-03-31 07:15:59.640418+00:00
    IST in Default Format :  2020-03-31 12:45:59.692642+05:30
    Date & Time in UTC :  2020:03:31 07:15:59 UTC+0000
    Date & Time in IST :  2020:03:31 12:45:59 IST+0530
    
    36

    pytz5

    Output:
    UTC in Default Format :  2020-03-31 07:15:59.640418+00:00
    IST in Default Format :  2020-03-31 12:45:59.692642+05:30
    Date & Time in UTC :  2020:03:31 07:15:59 UTC+0000
    Date & Time in IST :  2020:03:31 12:45:59 IST+0530
    
    38pytz9

    pytz5

    Output:
    UTC in Default Format :  2020-03-31 07:15:59.640418+00:00
    IST in Default Format :  2020-03-31 12:45:59.692642+05:30
    Date & Time in UTC :  2020:03:31 07:15:59 UTC+0000
    Date & Time in IST :  2020:03:31 12:45:59 IST+0530
    
    41
    Output:
    UTC in Default Format :  2020-03-31 07:15:59.640418+00:00
    IST in Default Format :  2020-03-31 12:45:59.692642+05:30
    Date & Time in UTC :  2020:03:31 07:15:59 UTC+0000
    Date & Time in IST :  2020:03:31 12:45:59 IST+0530
    
    35import3

    Output:
    UTC Format               IST Format
    2020-03-31 11:21:13 UTC +0000       2020-03-31 16:51:13 IST +0530
    2020-03-31 11:21:13 UTC +0000       2020-03-31 16:51:13 IST +0530
    2020-03-31 11:21:13 UTC +0000       2020-03-31 16:51:13 IST +0530
    2020-03-31 11:21:13 UTC +0000       2020-03-31 16:51:13 IST +0530
    2020-03-31 11:21:13 UTC +0000       2020-03-31 16:51:13 IST +0530
    

    Output:
    UTC in Default Format :  2020-03-31 07:15:59.640418+00:00
    IST in Default Format :  2020-03-31 12:45:59.692642+05:30
    Date & Time in UTC :  2020:03:31 07:15:59 UTC+0000
    Date & Time in IST :  2020:03:31 12:45:59 IST+0530
    
    11=
    Output:
    UTC in Default Format :  2020-03-31 07:15:59.640418+00:00
    IST in Default Format :  2020-03-31 12:45:59.692642+05:30
    Date & Time in UTC :  2020:03:31 07:15:59 UTC+0000
    Date & Time in IST :  2020:03:31 12:45:59 IST+0530
    
    13

    • Output:
      UTC in Default Format :  2020-03-31 07:15:59.640418+00:00
      IST in Default Format :  2020-03-31 12:45:59.692642+05:30
      Date & Time in UTC :  2020:03:31 07:15:59 UTC+0000
      Date & Time in IST :  2020:03:31 12:45:59 IST+0530
      
      14=
      Output:
      UTC in Default Format :  2020-03-31 07:15:59.640418+00:00
      IST in Default Format :  2020-03-31 12:45:59.692642+05:30
      Date & Time in UTC :  2020:03:31 07:15:59 UTC+0000
      Date & Time in IST :  2020:03:31 12:45:59 IST+0530
      
      16
    • Output:
      UTC in Default Format :  2020-03-31 07:15:59.640418+00:00
      IST in Default Format :  2020-03-31 12:45:59.692642+05:30
      Date & Time in UTC :  2020:03:31 07:15:59 UTC+0000
      Date & Time in IST :  2020:03:31 12:45:59 IST+0530
      
      17=
      Output:
      UTC in Default Format :  2020-03-31 07:15:59.640418+00:00
      IST in Default Format :  2020-03-31 12:45:59.692642+05:30
      Date & Time in UTC :  2020:03:31 07:15:59 UTC+0000
      Date & Time in IST :  2020:03:31 12:45:59 IST+0530
      
      19
    • Output:
      UTC in Default Format :  2020-03-31 07:15:59.640418+00:00
      IST in Default Format :  2020-03-31 12:45:59.692642+05:30
      Date & Time in UTC :  2020:03:31 07:15:59 UTC+0000
      Date & Time in IST :  2020:03:31 12:45:59 IST+0530
      
      20=
      Output:
      UTC in Default Format :  2020-03-31 07:15:59.640418+00:00
      IST in Default Format :  2020-03-31 12:45:59.692642+05:30
      Date & Time in UTC :  2020:03:31 07:15:59 UTC+0000
      Date & Time in IST :  2020:03:31 12:45:59 IST+0530
      
      22
    • Output:
      UTC in Default Format :  2020-03-31 07:15:59.640418+00:00
      IST in Default Format :  2020-03-31 12:45:59.692642+05:30
      Date & Time in UTC :  2020:03:31 07:15:59 UTC+0000
      Date & Time in IST :  2020:03:31 12:45:59 IST+0530
      
      23=
      Output:
      UTC in Default Format :  2020-03-31 07:15:59.640418+00:00
      IST in Default Format :  2020-03-31 12:45:59.692642+05:30
      Date & Time in UTC :  2020:03:31 07:15:59 UTC+0000
      Date & Time in IST :  2020:03:31 12:45:59 IST+0530
      
      25
    • Output:
      UTC in Default Format :  2020-03-31 07:15:59.640418+00:00
      IST in Default Format :  2020-03-31 12:45:59.692642+05:30
      Date & Time in UTC :  2020:03:31 07:15:59 UTC+0000
      Date & Time in IST :  2020:03:31 12:45:59 IST+0530
      
      26=
      Output:
      UTC in Default Format :  2020-03-31 07:15:59.640418+00:00
      IST in Default Format :  2020-03-31 12:45:59.692642+05:30
      Date & Time in UTC :  2020:03:31 07:15:59 UTC+0000
      Date & Time in IST :  2020:03:31 12:45:59 IST+0530
      
      28

    Làm thế nào để tôi có được thời gian chính xác trong Python?

    Ngoài mô-đun DateTime (), mô-đun thời gian là một cách tích hợp khác để có thời gian hiện tại trong Python.Như thường lệ, bạn phải nhập mô -đun thời gian trước và sau đó bạn có thể sử dụng phương thức ctime () để có được ngày và thời gian hiện tại.import the time module first, and then you can use the ctime() method to get the current date and time.

    Làm thế nào để tôi có được thời gian UTC hiện tại trong Python?

    Nhận thời gian UTC hiện tại..
    Sử dụng phương thức DateTime.now () để có thời gian hiện tại ..
    Sử dụng lớp timezone với phiên bản UTC với phương thức bây giờ () để có được thời gian UTC hiện tại trong Python ..

    Timezone bây giờ () trở lại là gì?

    Múi giờ.bây giờ () hữu ích.Hàm này trả về ngày và thời gian hiện tại dưới dạng DateTime ngây thơ khi uses_tz = false và dưới dạng dữ liệu nhận thức khi uses_tz = true.Bạn có thể thêm hoặc trừ DateTime.the current date and time as a naive datetime when USE_TZ = False and as an aware datetime when USE_TZ = True . You can add or subtract datetime.

    DateTime DateTime có phải không () UTC?

    Nhận dấu thời gian UTC sử dụng DateTime.DateTime.now () để có được ngày và thời gian hiện tại.Sau đó sử dụng lớp TZINFO để chuyển đổi DateTime của chúng tôi thành UTC.Use the datetime. datetime. now() to get the current date and time. Then use tzinfo class to convert our datetime to UTC.