2023年日期表 python實現

2022-08-16 15:54:17 字數 1458 閱讀 1957

import pandas as pd

import calendar

import datetime

# 生成日期範圍

date = pd.date_range("2020-01-01","2020-12-31",freq="d")

# 將日期轉化為字串

dt_str = [i.strftime("%y%m%d") for i in date]

# 日期對應的星期(數值)

week = [int(i.strftime("%w")) for i in date] # 0表示星期日

# 月份(數值,01,02,...)

month = [i.strftime("%m") for i in date]

# 月份(中文)

month_desc = [str(i) + "月" for i in month]

season = season_desc_info()

# 季度(中文)

season_desc = ["第" + str(i) + "季度" for i in season]

# 年份(數值)

year = [int(i.strftime("%y")) for i in date]

# 年份(中文)

year_desc = [ str(i) + "年" for i in year]

# 一年中的第幾天

date_seq = [int(i.strftime("%j")) for i in date]

# 一年中的第幾周

week_seq = [int(i.strftime("%u")) + 1 for i in date]

weekend_flag = is_weekend_flag()

monend_flag = is_month_lastday()

# 節假日標識

holiday_tp =

holiday_desc = is_holiday_desc()

weekend_desc = is_weekend_desc()

monend_desc = is_monend_desc()

xun_id = get_xun_id()

xun_desc = get_xun_desc()

# 周(數值)

week_seq_id =

def get_week_seq_id():

for i in date:

# 構造當前月的1號

first_day_of_month =datetime.date(i.year, i.month, 1)

week_seq_id=get_week_seq_id()

# 構造日期維表

dataframe = pd.dataframe()

dataframe.to_excel('./data/date2020.xlsx',index=false)

跨千年日期轉換

create orreplace function my to date p chr date invarchar2 return date is beginif p chr date isnull then return null elseif to date p chr date dd mm y...

Python3 日期相關

import datetime import time 獲取當前日期,格式化 date0 datetime.date.today strftime y m d h m s print date0 只有年月日 例如 20180927 00 00 00 date1 datetime.datetime.t...

Python學習 15 日期和時間

方法預覽 datetime.now 當前時間,datetime型別 datetime.timestamp 時間戳,浮點型別 datetime.strftime y m d h m s 格式化日期物件datetime,字串型別 datetime.strptime 2017 2 6 23 22 13 y...