Python
 Computer >> コンピューター >  >> プログラミング >> Python

PythonPandas-Timestampオブジェクトから現在の日付と時刻を取得します


Timestampオブジェクトから現在の日付と時刻を取得し、 timestamp.today()を使用します メソッド。

まず、必要なライブラリをインポートします-

import pandas as pd
import datetime

パンダでタイムスタンプを作成する

timestamp = pd.Timestamp(datetime.datetime(2021, 10, 10))

タイムスタンプを表示する

print("Timestamp: ", timestamp)

現在の日付と時刻を取得する

res = timestamp.today()

以下はコードです

import pandas as pd
import datetime

# set the timestamp in Pandas
timestamp = pd.Timestamp(datetime.datetime(2021, 10, 10))

# display the Timestamp
print("Timestamp: ", timestamp)

# display the day from given timestamp
print("Day Name:", timestamp.day_name())

# getting the current date and time
res = timestamp.today()

# display the current date and time
print("\nToday's Date and time...\n", res)

# display the current day
print("Today's Day:", res.day_name())

出力

これにより、次のコードが生成されます

Timestamp: 2021-10-10 00:00:00
Day Name: Sunday

Today's Date and time...
2021-10-03 13:22:28.891506
Today's Day: Sunday

  1. JavaScriptで現在の日付と時刻を取得するにはどうすればよいですか?

    JavaScriptで現在の日付と時刻を取得するには、getDate()メソッドを使用します。 例 次のコードを実行して、日付と時刻を取得してみてください。 <!DOCTYPE html> <html>    <body>       <p>Today's Date and Time</p>       <button onclick="myFunction()">Get Date & Time</b

  2. iOSでインターネットから現在の日付と時刻を取得するにはどうすればよいですか?

    日付と時刻の操作には注意が必要です。新しいプログラマーが日付と時刻に苦労しているのを見てきました。ほとんどすべてのアプリケーションでは、日付を取得する必要があり、複数の操作がそれに依存しています。 ここでは、現在の日付と時刻をすばやく取得する方法を説明します。 この投稿では、現在時刻とUTC時刻を取得する方法を説明します。 UTC時刻を取得するには、プレイグラウンドでコードの下に貼り付けてください。 let utcDate = Date() print(utcDate) 現在地のタイムスタンプを取得したい場合は、以下のコードを遊び場に貼り付けてください。 let dateObj = D