Dunny
Dunny

Reputation: 170

unix date command with nanosecond precision. Input parameter

I'm having difficulty parsing an inputted date with nanosecond precision:

date: invalid date `15-OCT-18 12:40:01:000203570 AM'

Yet when I drop the nanoseconds, it works fine:

$ date -d "15-OCT-18 12:40:01 AM" +"%d-%m-%Y %H:%M:%S %p"
15-10-2018 00:40:01 AM

Looking the docs its suggests uppercase N is to be used for ns

Even when I drop the Ns it generates the ns for me

$ date -d "15-OCT-18 12:40:01 AM" +"%d-%m-%Y %H:%M:%S:%N %p"
15-10-2018 00:40:01:000000000 AM

Upvotes: 0

Views: 606

Answers (2)

Dunny
Dunny

Reputation: 170

Should be in the format

date -d "15-OCT-18 12:40:01.000203570 AM" +"%d-%m-%Y %H:%M:%S:%N %p"

Data needs to have . instead of : spearating seconds and ns

Upvotes: 1

stack0114106
stack0114106

Reputation: 8711

You need to replace the : before the Nanoseconds identifier with .(dot)

> date -d"$(echo "15-OCT-18 12:40:01:000203570 AM" | sed 's/:/./3')" +"%d-%m-%Y %H:%M:%S.%N %p"
15-10-2018 00:40:01.000203570 AM
>

Upvotes: 0

Related Questions