高校物理160203 views
高校国語788336 views
高校化学2924392 views
雑学1473612 views
高校日本史190571 views
小学社会310485 views
英語613639 views
小学算数1200427 views
りんご209490 views
高校生物551766 views
Help
Tools
NewsSpreadsheetCalendarSlidesTier ListPen ToolIllustrationCrayonPixel ArtASCII ArtPerspectiveEndless StairsGraphMind MapER DiagramFamily TreeMemeCurved TextImage EditorMosaicRetro FilterPencil SketchOCR/HighlighterMakeup EditorFaviconVideo TrimmerScrolling VideoVideo TitleColor PickerColor ExtractorBonfireFireworksWater RippleWater SplashBreaking GlassWood GrainMarble TextureCSS ButtonIcon MakerBar ChartGrouped Bar ChartStacked Bar ChartPie ChartLine ChartArea ChartStacked Area ChartScatter Plot3D Bar Chart3D Pie ChartBar Chart RaceBubble ChartPopulation PyramidPictogramEarningsCandlestick ChartInvestment RiskMortgage SimulatorCalculatorMatrix CalculatorFunction GraphPolynomial ExpansionVenn DiagramField VisualizerRubik's Cube Group TheoryTraveling SalesmanVoronoi and DelaunayFractalColumn ArithmeticDraw Math FiguresArithmetic AnimationArithmetic Word ProblemsCounting with Tree DiagramsCube NetsCross SectionsMotion PathMechanicsWavesLight and LensesThermodynamicsHow Semiconductors WorkMolecular StructuresAtomic OrbitalsElectrochemical CellsChemical EquilibriumCrystal LatticesBuffer pHComplex IonsDNA Double HelixCell DivisionMembrane ChannelsNerve ImpulseRock ClassificationWeatherConstellationsSolar and Lunar Eclipses3D ModelingFloor PlanSeismic StructuresIntersection TurnMaglevCooking AnimationOrigamiLive Viewer CountGeoJSON MapRailway MapPopulation MapCrime MapLand Price MapSchool MapShrine and Castle MapHouse of Representatives MapWord MapSolitaireReversiHakoiri MusumeChessHamburgerRippleSlide Puzzle MakerNeon PinballNovel MakerJapanese Typing PracticePiano Score EditorMusic Theory

English

Python で今日と明後日の曜日を英語と日本語で取得する

Python で明日や明後日の情報を取得するときは、まず今日のデータを datetime で得る。

from datetime import datetime, timedelta

today = datetime.today()

tomorrow = today + timedelta(days=1)
day_after_tomorrow = today + timedelta(days=2)

tomorrow_weekday = tomorrow.strftime("%A")
day_after_tomorrow_weekday = day_after_tomorrow.strftime("%A")

print("Tomorrow:", tomorrow_weekday)
print("Day after tomorrow:", day_after_tomorrow_weekday)

# Tomorrow: Wednesday
# Day after tomorrow: Thursday

明日 = 今日 + 1

といった要領で、timedelta の引数を設定すれば、明日と明後日のデータができる。

日本語で曜日を取得する場合

weekday() は月曜を 0、日曜を 6 として整数を返す。

from datetime import datetime, timedelta

today = datetime.today()

tomorrow = today + timedelta(days=1)
day_after_tomorrow = today + timedelta(days=2)

weekdays = ["月曜日", "火曜日", "水曜日", "木曜日", "金曜日", "土曜日", "日曜日"]

tomorrow_weekday = weekdays[tomorrow.weekday()]
day_after_tomorrow_weekday = weekdays[day_after_tomorrow.weekday()]

print("明日:", tomorrow_weekday)
print("明後日:", day_after_tomorrow_weekday)

# 明日: 水曜日
# 明後日: 木曜日