時間模塊,帶Python示例

Python時間模塊 (Python time Module)

The time module is a built-in module in Python and it has various functions that require to perform more operations on time. This is one of the best modules in Python that used to solve various real-life time-related problems. To use the time module in the program, initially, we have to import the time module.

時間模塊是Python中的內置模塊,它具有各種功能,需要按時執行更多操作。 這是Python中最好的模塊之一,用于解決各種現實中與時間相關的問題。 要在程序中使用時間模塊,首先,我們必須導入時間模塊

This module begins the recording time from the epoch. Epoch means time in history and it begins on 1st January 1970.

此模塊從紀元開始記錄時間。 歷元是歷史上的時間,始于1970年1月1日。

時間模塊的一些重要功能 (Some important function of the time module)

1次() (1) time())

This function returns the number of the second count since the epoch.

此函數返回自紀元以來的第二個計數的編號。

Example:

例:

# Importing the module
import time
s=time.time()
print('Total seconds since epoch:',s)

Output

輸出量

Total seconds since epoch: 1576083939.5877264

2)ctime() (2) ctime())

This function of the time module takes second as an argument and return time till the mentioned seconds.

時間模塊的此功能以秒為參數,并返回時間直到提到的秒數。

Example:

例:

# Importing the module
import time
s=1575293263.821702
Current_time=time.ctime(s)
print('current time since epoch:',Current_time)

Output

輸出量

current time since epoch: Mon Dec  2 13:27:43 2019

3)sleep() (3) sleep())

This function is used to stay the program execution for the time given in the arguments of this function.

該函數用于在該函數的參數中指定的時間內保持程序執行。

Example:

例:

# Importing the module
import time
print('Execution starting time:',time.ctime())
time.sleep(5)
print('After execution time:',time.ctime())

Output

輸出量

Execution starting time: Wed Dec 11 17:10:47 2019
After execution time: Wed Dec 11 17:10:52 2019

4)strftime() (4) strftime())

This function takes an argument and returns a string based on the format code.

該函數接受一個參數,并根據格式代碼返回一個字符串。

Example:

例:

# Importing the module
import time
Current_time=time.localtime() 
time_in_format=time.strftime("%m/%d/%Y, %H:%M:%S",Current_time)
print('time in specific format since epoch:',time_in_format)

Output

輸出量

time in specific format since epoch: 12/11/2019, 17:12:47

5)asctime() (5) asctime())

This function takes a tuple of length nine as an argument and returns a string.

此函數將長度為9的元組作為參數并返回一個字符串。

Example:

例:

# Importing the module
import time
t=(2019,12,2,5,30,2,7,365,0)
r=time.asctime(t)
print("Time and date in a specific format:",r)

Output

輸出量

Time and date in a specific format: Mon Dec  2 05:30:02 2019

翻譯自: https://www.includehelp.com/python/time-module-with-example.aspx

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/377590.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/377590.shtml
英文地址,請注明出處:http://en.pswp.cn/news/377590.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

五、torchvision

一、下載CIFAR-10數據集 CIFAR-10數據集官網 通過閱讀官網給的解釋可以大概了解到,一共6w張圖片,每張圖片大小為3232,5w張訓練圖像,1w張測試圖像,一共由十大類圖像。 CIFAR10官網使用文檔 torchvision.datasets.CIF…

leetcode 69. x 的平方根 思考分析

題目 實現 int sqrt(int x) 函數。 計算并返回 x 的平方根,其中 x 是非負整數。 由于返回類型是整數,結果只保留整數的部分,小數部分將被舍去。 示例 1: 輸入: 4 輸出: 2 示例 2: 輸入: 8 輸出: 2 說明: 8 的平方根是 2.82842…, 由于返回…

背包問題 小灰_小背包問題

背包問題 小灰Prerequisites: Algorithm for fractional knapsack problem 先決條件: 分數背包問題算法 Here, we are discussing the practical implementation of the fractional knapsack problem. It can be solved using the greedy approach and in fraction…

360瀏覽器兼容問題

360瀏覽器兼容問題 360瀏覽器又是一大奇葩,市場份額大,讓我們不得不也對他做些兼容性處理。 360瀏覽器提供了兩種瀏覽模式,極速模式和兼容模式,極速模式下是webkit內核的處理模式,兼容模式下是與IE內核相同的處理模式。…

轉 設計師也需要了解的一些前端知識

一、常見視覺效果是如何實現的 一些事 關于文字效果 互聯網的一些事 文字自身屬性相關的效果css中都是有相對應的樣式的,如字號、行高、加粗、傾斜、下劃線等,但是一些特殊的效果,主要表現為ps中圖層樣式中的效果,css是無能為力的…

六、DataLoader

一、DataLoader參數解析 DataLoader官網使用手冊 參數描述dataset說明數據集所在的位置、數據總數等batch_size每次取多少張圖片shuffleTrue亂序、False順序(默認)samplerbatch_samplernum_workers多進程,默認為0采用主進程加載數據collate_fnpin_memorydrop_las…

單調棧 leetcode整理(一)

目錄單調棧知識402. 移掉K位數字1673. 找出最具競爭力的子序列316. 去除重復字母(1081. 不同字符的最小子序列)321. 拼接最大數單調棧知識 單調棧就是一個內部元素有序的棧(大->小 or 小->大),但是只用到它的一…

數字簽名 那些密碼技術_密碼學中的數字簽名

數字簽名 那些密碼技術A signature is usually used to bind signatory to the message. The digital signature is thus a technique that binds a person or the entity to the digital data. This binding ensures that the person sending the data is solely responsible …

七、torch.nn

一、神經網絡模塊 進入到PyTorch的torch.nnAPI學習頁面 PyTorch提供了很多的神經網絡方面的模塊,NN就是Neural Networks的簡稱 二、Containers torch.nn下的Containers 一共有六個模塊,最常用的就是Module模塊,看解釋可以知道&#xff0c…

Java多線程初學者指南(8):從線程返回數據的兩種方法

本文介紹學習Java多線程中需要學習的從線程返回數據的兩種方法。從線程中返回數據和向線程傳遞數據類似。也可以通過類成員以及回調函數來返回數據。原文鏈接 從線程中返回數據和向線程傳遞數據類似。也可以通過類成員以及回調函數來返回數據。但類成員在返回數據和傳遞數據時有…

【C++進階】 遵循TDD原則,實現平面向量類(Vec2D)

目錄1、明確要實現的類的方法以及成員函數2、假設已經編寫Vec2D,根據要求,寫出測試代碼3、編寫平面向量類Vec2D,并進行測試4、完整代碼5、最終結果1、明確要實現的類的方法以及成員函數 考慮到效率問題,我們一般將函數的參數設置為引用類型。…

Keilc的中斷號計算方法

中斷號碼 (中斷向量-3)/8轉載于:https://www.cnblogs.com/yuqilihualuo/p/3423634.html

md5模式 簽名_MD的完整形式是什么?

md5模式 簽名醫師:醫學博士/常務董事 (MD: Doctor of Medicine / Managing Director) 1)醫學博士:醫學博士 (1) MD: Doctor of Medicine) MD is an abbreviation of a Doctor of Medicine degree. In the field of Medicine, it is the main academic de…

八、卷積層

一、Conv2d torch.nn.Conv2d官網文檔 torch.nn.Conv2d(in_channels, out_channels, kernel_size, stride1, padding0, dilation1, groups1, biasTrue, padding_modezeros, deviceNone, dtypeNone) 參數解釋官網詳情說明in_channels輸入的通道數,如果是彩色照片通道…

HTMl5結構元素:header

頁眉header 頁眉將是頁面加載的第一個元素&#xff0c;包含了站點的標題、logo、網站導航等。<header> <div class"container_16"> <div class"logo"> <h1><a href"index.html"><strong>Real</st…

【C++grammar】左值、右值和將亡值

目錄C03的左值和右值C11的左值和右值將亡值在C03中就有相關的概念 C03的左值和右值 通俗的理解&#xff1a; (1) 能放在等號左邊的是lvalue (2) 只能放在等號右邊的是rvalue (3) lvalue可以作為rvalue使用 對于第三點可以舉個例子&#xff1a; int x ; x 6; //x是左值&#…

scala字符串的拉鏈操作_在Scala中對字符串進行操作

scala字符串的拉鏈操作Scala字符串操作 (Scala strings operation) A string is a very important datatype in Scala. This is why there are a lot of operations that can be done on the string object. Since the regular operations like addition, subtraction is not v…

九、池化層

一、Pooling layers Pooling layers官網文檔 MaxPool最大池化層下采樣 MaxUnpool最大池化層上采樣 AvgPool最大池化層平均采樣 例如&#xff1a;池化核為(3,3)&#xff0c;輸入圖像為(5,5)&#xff0c;步長為1&#xff0c;不加邊 最大池化就是選出在池化核為單位圖像中的最大…

[分享]SharePoint移動設備解決方案

老外寫的一個PPT&#xff0c;講SharePoint在移動領域的應用&#xff0c;2012年最新的&#xff0c;有iPad喲。/Files/zhaojunqi/SharePoint2010andMobileDevices.pdf 轉載于:https://www.cnblogs.com/zhaojunqi/archive/2012/04/12/2444712.html

十、非線性激活函數

一、ReLU torch.nn.ReLU(inplaceFalse)官網提供的API 其中inplace表示是否在對原始數據進行替換 由函數圖可以看出&#xff0c;負數通過ReLU之后會變成0&#xff0c;正數則不發生變化 例如&#xff1a;input -1&#xff0c;若inplace True&#xff0c;表示對原始輸入數據進…