Strip microsecond from datetime

sahithya

For a given timedata - 2018-06-01 06:36:40.047883+00:00, I want to remove microsecond and strip the value after '+'. Most of my dataset contains values like 2018-06-04 11:30:00+00:00 without the microsecond part.

How to have a common date time format for all values?

tpk

I'm answering your question with an assumption that the type of the data is a string.

If you are facing problem in handling in different formats like "2018-06-01 06:36:40.047883+00:00" and "2018-06-04 11:30:00+00:00" you can use split(). Learn more about split() at here

str_data_time.split("+")[0].split(".")[0]

Like,

for str_data_time in ["2018-06-01 06:36:40.047883+00:00", "2018-06-04 11:30:00+00:00"]:
    output = str_data_time.split("+")[0].split(".")[0]
    print(output)

The output of the above script is,

2018-06-01 06:36:40
2018-06-04 11:30:00

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Strip all whitespace from a string

分類Dev

Strip comments from javascript file

分類Dev

strip a file from empty lines

分類Dev

Regex to strip jsessionid from URL

分類Dev

Strip hidden whitespace from string

分類Dev

Strip newline from piped input

分類Dev

Strip time zone part from Time in Ruby

分類Dev

how strip commas from string in Elixir?

分類Dev

Strip prefix from all variable names in SPSS

分類Dev

Strip date from filename using batch script

分類Dev

Strip out numbers from text: R

分類Dev

Strip radiotap headers from a pcap file

分類Dev

Timestamp column with microsecond precision

分類Dev

How to strip out header from base 64 image in C#?

分類Dev

Strip trailing spaces from factor labels using dplyr chain

分類Dev

How to strip or replace all matches of a pattern from a string in Bash?

分類Dev

How to use AWS API Gateway to strip parameters from URL?

分類Dev

how to strip unwanted text from column in pandas dataframe

分類Dev

How to strip first and last byte from binary data in Python

分類Dev

How can I strip out all HTML from my string

分類Dev

How to strip non-alphabetic, spaces and numeric characters from a string?

分類Dev

Get the closest datetime from a list

分類Dev

Convert datetime from Excel to R

分類Dev

From number to formatted datetime in R

分類Dev

convert from long timestamp to datetime

分類Dev

Delay by 1 microsecond in C MIPS Environment

分類Dev

PC wakes from sleep, when i plug in laptop to the same power strip the PC is plugged into

分類Dev

xarray/datetime64[ns]: remove or normalise time from datetime

分類Dev

Convert from List<Dictionary<DateTime, Points[]>> to Dictionary<DateTime, Points[]>

Related 関連記事

ホットタグ

アーカイブ