【Pythonプログラミング入門】日付・時間の操作の基本を解説!(datetime)

Pythonプログラミングに関する情報を発信しているサプーです! 
この動画はPythonの日付と時間の操作の基本について解説しています。

・datetimeで時間と日付を操作する
・timedeltaで日付の差分を扱う
・タイムゾーンとは?
・日本の祝日(jpholiday)について
これらについて説明しています💙

実際にPythonコードを動かして実演しているので、最後まで見てもらえたら嬉しいです😊

⭐️ チャプター ⭐️
0:00 今日のテーマ「Pythonの日付・時間の操作の基本」
0:25 dateオブジェクト
2:33 timeオブジェクト
3:04 datetimeオブジェクト
7:08 タイムゾーン
9:52 日本の祝日
12:19 エンディング

#python 
#programming 

What is GEEK

Buddha Community

【Pythonプログラミング入門】日付・時間の操作の基本を解説!(datetime)

【Pythonプログラミング入門】日付・時間の操作の基本を解説!(datetime)

Pythonプログラミングに関する情報を発信しているサプーです! 
この動画はPythonの日付と時間の操作の基本について解説しています。

・datetimeで時間と日付を操作する
・timedeltaで日付の差分を扱う
・タイムゾーンとは?
・日本の祝日(jpholiday)について
これらについて説明しています💙

実際にPythonコードを動かして実演しているので、最後まで見てもらえたら嬉しいです😊

⭐️ チャプター ⭐️
0:00 今日のテーマ「Pythonの日付・時間の操作の基本」
0:25 dateオブジェクト
2:33 timeオブジェクト
3:04 datetimeオブジェクト
7:08 タイムゾーン
9:52 日本の祝日
12:19 エンディング

#python 
#programming 

August  Larson

August Larson

1624286940

Datetime module in Python

A guide to understanding the datetime module in Python.

Time

This module helps deal with timestamps. The time class has attributes like hour, minute, second and microsecond.

>>> import datetime

Let’s create a timestamp. The arguments are in the following order — hour, minutes, seconds, microseconds, time zone information.

>>> t1 = datetime.time(6, 4, 2)

>>> print(t1)
06:04:02

As you can there are various methods which can be used.

>>> t1.hour
6

>>> t1.minute
4
>>> t1.microsecond
0
>>> print(t1.tzinfo)
None

We can also get the minimum and maximum time we can have.

>>> print(datetime.time.min)
00:00:00

>>> print(datetime.time.max)
23:59:59.999999

#programming #coding #python3 #datetime #python #datetime module in python

A Dart Library That Expand DateTime

TODO: Put a short description of the package here that helps potential users know whether this package might be useful for them.

Features

  • get the sexagenary cycle(60-year cycle) in chinese date(干支).
  • get the era name of japanese in japanese date(日本年号).
  • get some information about month. like:
    • first day, last day
    • for each day (normal, reverse, async)
    • count of days

Getting started

  • import it like import 'package:big_date/big_date.dart';

Usage

first you must imort this package to use it.

import 'package:big_date/big_date.dart';

and then you can use it like this

Additional information

TODO: Tell users more about the package: where to find more information, how to contribute to the package, how to file issues, what response they can expect from the package authors, and more.

Use this package as a library

Depend on it

Run this command:

With Dart:

 $ dart pub add big_date

With Flutter:

 $ flutter pub add big_date

This will add a line like this to your package's pubspec.yaml (and run an implicit dart pub get):

dependencies:
  big_date: ^0.2.2

Alternatively, your editor might support dart pub get or flutter pub get. Check the docs for your editor to learn more.

Import it

Now in your Dart code, you can use:

import 'package:big_date/big_date.dart'; 

example/big_date_example.dart

import 'package:big_date/big_date.dart';

void main() {
  final now = DateTime.now();
  print(now.lastMonth.lastMonth.lastMonth.dayCountOfMonth);
  DateTime.now().forEachDayOfMonthReverse((d) => print(d));
  print(now.format("%w"));
  print(now.toJapanDate().format("%W"));
  print(now.format("%_w"));
  print(now.toJapanDate().format("%_W"));
} 

Download Details:

Author: normidar

Source Code: https://github.com/normidar/big_date

#datetime #dart #ios #android 

A Flutter DateTime Picker Package

Omni DateTime Picker

A DateTime picker that lets user select a date and the time, with start & end as a range.

Screenshots

Omni DateTime Picker - Light

Omni DateTime Range Picker - Dark

Getting started

Add this to your package's pubspec.yaml file and run flutter pub get:

dependencies:
  omni_datetime_picker: ^0.1.2

Now in your Dart code, you can use:

import 'package:omni_datetime_picker/omni_datetime_picker.dart';

Usage

Simple usage:

OmniDateTimePicker

DateTime? dateTime = await showOmniDateTimePicker(context: context);

OmniDateTimeRangePicker

List<DateTime>? dateTimeList = await showOmniDateTimeRangePicker(context: context);

Custom properties:

OmniDateTimePicker

DateTime? dateTime = await showOmniDateTimePicker(
              context: context,
              type: OmniDateTimePickerType.dateAndTime,
              primaryColor: Colors.cyan,
              backgroundColor: Colors.grey[900],
              calendarTextColor: Colors.white,
              tabTextColor: Colors.white,
              unselectedTabBackgroundColor: Colors.grey[700],
              buttonTextColor: Colors.white,
              timeSpinnerTextStyle:
                  const TextStyle(color: Colors.white70, fontSize: 18),
              timeSpinnerHighlightedTextStyle:
                  const TextStyle(color: Colors.white, fontSize: 24),
              is24HourMode: false,
              isShowSeconds: false,
              startInitialDate: DateTime.now(),
              startFirstDate:
                  DateTime(1600).subtract(const Duration(days: 3652)),
              startLastDate: DateTime.now().add(
                const Duration(days: 3652),
              ),
              borderRadius: const Radius.circular(16),
            );

OmniDateTimeRangePicker

List<DateTime>? dateTimeList = await showOmniDateTimeRangePicker(
              context: context,
              type: OmniDateTimePickerType.dateAndTime,
              primaryColor: Colors.cyan,
              backgroundColor: Colors.grey[900],
              calendarTextColor: Colors.white,
              tabTextColor: Colors.white,
              unselectedTabBackgroundColor: Colors.grey[700],
              buttonTextColor: Colors.white,
              timeSpinnerTextStyle:
                  const TextStyle(color: Colors.white70, fontSize: 18),
              timeSpinnerHighlightedTextStyle:
                  const TextStyle(color: Colors.white, fontSize: 24),
              is24HourMode: false,
              isShowSeconds: false,
              startInitialDate: DateTime.now(),
              startFirstDate:
                  DateTime(1600).subtract(const Duration(days: 3652)),
              startLastDate: DateTime.now().add(
                const Duration(days: 3652),
              ),
              endInitialDate: DateTime.now(),
              endFirstDate: DateTime(1600).subtract(const Duration(days: 3652)),
              endLastDate: DateTime.now().add(
                const Duration(days: 3652),
              ),
              borderRadius: const Radius.circular(16),
            );

The returned value of showOmniDateTimeRangePicker() will be a List with two DateTime: [startDateTime, endDateTime].

Use this package as a library

Depend on it

Run this command:

With Flutter:

 $ flutter pub add omni_datetime_picker

This will add a line like this to your package's pubspec.yaml (and run an implicit flutter pub get):

dependencies:
  omni_datetime_picker: ^0.1.2

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

Import it

Now in your Dart code, you can use:

import 'package:omni_datetime_picker/omni_datetime_picker.dart'; 

example/main.dart

import 'package:flutter/material.dart';
import 'package:omni_datetime_picker/omni_datetime_picker.dart';

class MyApp extends StatefulWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Omni DateTime Picker',
      debugShowCheckedModeBanner: false,
      home: Scaffold(
        body: Center(
          child: Column(
            children: [
              ElevatedButton(
                onPressed: () async {
                  DateTime? dateTime =
                      await showOmniDateTimePicker(context: context);
                },
                child: const Text("Show DateTime Picker"),
              ),
              ElevatedButton(
                onPressed: () async {
                  List<DateTime>? dateTimeList =
                      await showOmniDateTimeRangePicker(
                    context: context,
                    primaryColor: Colors.cyan,
                    backgroundColor: Colors.grey[900],
                    calendarTextColor: Colors.white,
                    tabTextColor: Colors.white,
                    unselectedTabBackgroundColor: Colors.grey[700],
                    buttonTextColor: Colors.white,
                    timeSpinnerTextStyle:
                        const TextStyle(color: Colors.white70, fontSize: 18),
                    timeSpinnerHighlightedTextStyle:
                        const TextStyle(color: Colors.white, fontSize: 24),
                    is24HourMode: false,
                    isShowSeconds: false,
                    startInitialDate: DateTime.now(),
                    startFirstDate:
                        DateTime(1600).subtract(const Duration(days: 3652)),
                    startLastDate: DateTime.now().add(
                      const Duration(days: 3652),
                    ),
                    endInitialDate: DateTime.now(),
                    endFirstDate:
                        DateTime(1600).subtract(const Duration(days: 3652)),
                    endLastDate: DateTime.now().add(
                      const Duration(days: 3652),
                    ),
                    borderRadius: const Radius.circular(16),
                  );
                },
                child: const Text("Show DateTime Range Picker"),
              ),
              ElevatedButton(
                onPressed: () async {
                  List<DateTime>? dateTimeList =
                      await showOmniDateTimeRangePicker(
                    context: context,
                    type: OmniDateTimePickerType.date,
                    primaryColor: Colors.cyan,
                    backgroundColor: Colors.grey[900],
                    calendarTextColor: Colors.white,
                    tabTextColor: Colors.white,
                    unselectedTabBackgroundColor: Colors.grey[700],
                    buttonTextColor: Colors.white,
                    timeSpinnerTextStyle:
                        const TextStyle(color: Colors.white70, fontSize: 18),
                    timeSpinnerHighlightedTextStyle:
                        const TextStyle(color: Colors.white, fontSize: 24),
                    is24HourMode: false,
                    isShowSeconds: false,
                    startInitialDate: DateTime.now(),
                    startFirstDate:
                        DateTime(1600).subtract(const Duration(days: 3652)),
                    startLastDate: DateTime.now().add(
                      const Duration(days: 3652),
                    ),
                    endInitialDate: DateTime.now(),
                    endFirstDate:
                        DateTime(1600).subtract(const Duration(days: 3652)),
                    endLastDate: DateTime.now().add(
                      const Duration(days: 3652),
                    ),
                    borderRadius: const Radius.circular(16),
                  );
                },
                child: const Text("Show DateTime Range Picker without Time"),
              ),
            ],
          ),
        ),
      ),
    );
  }
} 

Download Details:

Author: Type0N1

Source Code: https://github.com/Type0N1/OmniDateTimePicker

#picker #datetime #flutter 

Anna Yusef

Anna Yusef

1610755980

Converting Strings to DateTime in Python

Dealing with dates and times in Python can be messy while analyzing the datasets. There are a lot of informations to take into account, such as the year, the month, the day, the hour, the minutes, the seconds, but also more complex features as the duration, the weekday, the timezones. For this reason, I will talk about a Python module, that manipulates this type of information: datetime[1].

The datasets often have the dates represented as strings and you need to convert them to datetime format in order to work with time series data. In this tutorial, I will explain the library with some examples to easily understand how to deal with this data.

#timeseries #datetime #convertion #python