python 的datetime模塊使用

1.datetime模塊主要是5個類

  date #日期類 年月日?datetime.date(year,month,day)

  time #時間類 時分秒?datetime.time(hour,minute,second,microsecond,tzoninfo),返回18:29:30

  datetime #日期時間類?datetime(year, month, day[, hour[, minute[, second[, microsecond[,tzinfo]]]]])

  timedelta #兩個時間點的間隔

  tzinfo #時區

2.使用到的方法

  datetime.date.isocalendar() #返回年月日的元祖(2018,9,29)

  datetime.date.isoweekday() #返回給定日期的星期(1~7)

  datetime.date.strftime(format) #已指定日期返回

  ......使用到再記錄

3.使用到的日期相關

%y 兩位數的年份表示(00-99)

%Y 四位數的年份表示(000-9999)

%m 月份(01-12)

%d 月內中的一天(0-31)

%H 24小時制小時數(0-23)

%I 12小時制小時數(01-12)

%M 分鐘數(00=59)

%S 秒(00-59)

4.使用中的例子

import datetime

class timeUtil:
#昨天
def day_get(self,d):
oneday = datetime.timedelta(days=1)
day = d - oneday
date_from = datetime.date(day.year, day.month, day.day).strftime('%Y%m%d')
date_to = datetime.date(day.year, day.month, day.day).strftime('%Y%m%d')
return '&endTime='.join([str(date_from), str(date_to)])
#本周
def week_get(self,d):
dayscount = datetime.timedelta(days=d.isoweekday() - 1)
dayto = d - dayscount
sixdays = datetime.timedelta(days=6)
dayfrom = dayto + sixdays
date_to = datetime.date(dayfrom.year, dayfrom.month, dayfrom.day).strftime('%Y%m%d')
date_from = datetime.date(dayto.year, dayto.month, dayto.day).strftime('%Y%m%d')
return '&endTime='.join([str(date_from), str(date_to)])
#當前月
def month_get(self,d):
dayscount = datetime.timedelta(days=d.day - 1)
dayfrom = d - dayscount
date_from = datetime.date(dayfrom.year, dayfrom.month, 1).strftime('%Y%m%d')
date_to = datetime.date(d.year, d.month, d.day).strftime('%Y%m%d')
print '&endTime='.join([str(date_from), str(date_to)])

?

  

?

轉載于:https://www.cnblogs.com/xierunfang/p/9726188.html

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

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

相關文章

物聯網數據可視化_激發好奇心:數據可視化如何增強博物館體驗

物聯網數據可視化When I was living in Paris at the beginning of this year, I went to a minimum of three museums a week. While this luxury was made possible by the combination of an ICOM card and unemployment, it was founded on a passion for museums. Looking…

計算機公開課教學反思,語文公開課教學反思

語文公開課教學反思引導語: 在語文的公開課結束后,教師們在教學 有哪些需要反思的呢?接下來是yjbys小編為大家帶來的關于語文公開課教學反思,希望會給大家帶來幫助。篇一:語文公開課教學反思今天早上,我上了一節語文…

中國連續十年成馬來西亞最大貿易伙伴

中新社吉隆坡1月30日電 (記者 陳悅)馬來西亞國際貿易和工業部30日發布的2018年馬來西亞貿易報告顯示,2018年馬來西亞與中國的貿易額約為3138.1億林吉特(馬來西亞貨幣,約合774億美元),較上年同期增長8.1%,約占馬來西亞對外貿易總額…

Iphone NSMutableArray,NSMutableDictionary AND 動態添加按鈕

一.NSMutableDictionary NSMutableDictionary * tags; 1.NSMutableDictionary 添加內容: [tags setValue:xxx forKey :xxx]; 2.NSMutableDictionary 遍歷: for(NSString * title in tags){ //其中得到的title是key } 3.NSMutableD…

bzoj2938: [Poi2000]病毒

被Star_Feel大爺帶著做題 明顯大力AC機然后找環 本來我一開始想的是先去有另一個病毒為前綴的病毒,結果今天早上寫的時候偷懶沒寫 結果跳fail的時候會跳到中間。。。無語,Star_Feel大爺叫我son或一下now和fail就過了 還有神仙是直接把fail接到兒子的更流…

bigquery數據類型_將BigQuery與TB數據一起使用后的成本和性能課程

bigquery數據類型I’ve used BigQuery every day with small and big datasets querying tables, views, and materialized views. During this time I’ve learned some things, I would have liked to know since the beginning. The goal of this article is to give you so…

中國計算機學科建設,計算機學科建設戰略研討會暨“十四五”規劃務虛會召開...

4月15日下午,信息學院計算機系舉辦了計算機科學與技術學科建設戰略研討會暨“十四五”規劃務虛會。本次會議的主旨是借第五輪學科評估的契機,總結計算機學科發展的優劣勢,在強調保持優勢的同時,更著眼于短板和不足,在未…

iphone開發如何隱藏各種bar

轉載至:http://blog.csdn.net/riveram/article/details/7291142 狀態條StatusBar [cpp] view plaincopyprint?[UIApplication sharedApplication].statusBarHidden YES; [UIApplication sharedApplication].statusBarHidden YES; 導航條NavigationBar [cpp] v…

Swift5.1 語言指南(九) 閉包

★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★?微信公眾號:山青詠芝(shanqingyongzhi)?博客園地址:山青詠芝(https://www.cnblogs.com/strengthen/)?GitHub地址&a…

服務器被攻擊怎么修改,服務器一直被攻擊怎么辦?

原標題:服務器一直被攻擊怎么辦?有很多人問說,網站一直被攻擊,什么被掛馬,什么被黑,每天一早打開網站,總是會出現各種各樣的問題,這著實讓站長們揪心。從修改服務器管理賬號開始&…

腳本 api_從腳本到預測API

腳本 apiThis is the continuation of my previous article:這是我上一篇文章的延續: From Jupyter Notebook To Scripts從Jupyter Notebook到腳本 Last time we discussed how to convert Jupyter Notebook to scripts, together with all sorts of basic engine…

Iphone代碼創建視圖

要想以編程的方式創建視圖,需要使用視圖控制器中定義的viewDidLoad方法,只有在運行期間生成UI時才需要實現該方法。 在此只貼出viewDidLoad方法的代碼,因為只需要在這個方法里面編寫代碼: [cpp] view plaincopyprint?- (void)vi…

聊聊flink Table的OrderBy及Limit

序 本文主要研究一下flink Table的OrderBy及Limit 實例 Table in tableEnv.fromDataSet(ds, "a, b, c"); Table result in.orderBy("a.asc");Table in tableEnv.fromDataSet(ds, "a, b, c");// returns the first 5 records from the sorted …

binary masks_Python中的Masks概念

binary masksAll men are sculptors, constantly chipping away the unwanted parts of their lives, trying to create their idea of a masterpiece … Eddie Murphy所有的人都是雕塑家,不斷地消除生活中不必要的部分,試圖建立自己的杰作理念……埃迪墨…

css+沿正方形旋轉,CSS3+SVG+JS 正方形沿著正方本中軸移動翻轉的動畫

CSS語言:CSSSCSS確定* {margin: 0;padding: 0;fill: currentColor;vector-effect: non-scaling-stroke;}html {overflow: hidden;}body {display: flex;flex-direction: column;margin: 0;min-width: 10em;height: 100vh;}body > svg,body > input,body > …

Iphone在ScrollView下點擊TextField使文本筐不被鍵盤遮住

1.拖一個Scroll View視圖填充View窗口&#xff0c;將Scroll View視圖拖大一些&#xff0c;使其超出屏幕。 2.向Scroll View拖&#xff08;添加&#xff09;多個Label視圖和Text View視圖。 3.在.h頭文件中添加如下代碼&#xff1a; [cpp] view plaincopyprint?#import <U…

兩高發布司法解釋 依法嚴懲涉地下錢莊犯罪

新華社北京1月31日電&#xff08;記者丁小溪&#xff09;最高人民法院、最高人民檢察院31日聯合發布關于辦理非法從事資金支付結算業務、非法買賣外匯刑事案件適用法律若干問題的解釋&#xff0c;旨在依法懲治非法從事資金支付結算業務、非法買賣外匯犯罪活動&#xff0c;維護金…

python 儀表盤_如何使用Python刮除儀表板

python 儀表盤Dashboard scraping is a useful skill to have when the only way to interact with the data you need is through a dashboard. We’re going to learn how to scrape data from a dashboard using the Selenium and Beautiful Soup packages in Python. The S…

VS2015 定時服務及控制端

一. 服務端 如下圖—新建項目—經典桌面—Windows服務—起名svrr2. 打到server1 改名為svrExecSqlInsert 右擊對應的設計界面&#xff0c;添加安裝服務目錄結構如圖 3. svrExecSqlInsert里有打到OnStart()方法開始寫代碼如下 /// <summary>/// 服務開啟操作/// </su…

css文件如何設置scss,Webpack - 如何將scss編譯成單獨的css文件?

2 個答案:答案 0 :(得分&#xff1a;3)這是我在嘗試將css編譯成單獨文件時使用的webpack.config.js文件|-- App|-- dist|-- src|-- css|-- header.css|-- sass|-- img|-- partials|-- _variables.scss|-- main.scss|--ts|-- tsconfig.json|-- user.ts|-- main.js|-- app.js|-- …