Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question Convert date to milliseconds (epoch millis) #144

Open
mailsanchu opened this issue May 18, 2022 · 4 comments
Open

Question Convert date to milliseconds (epoch millis) #144

mailsanchu opened this issue May 18, 2022 · 4 comments

Comments

@mailsanchu
Copy link

How do i get epoc milliseconds from a custom date
dateconv "20220518181552" -i '%Y%m%d%H%M%S' -f %rs
gives me epoch second But how do i get milli second

@hroptatyr
Copy link
Owner

Hi, pragmatically you could do

$ "20220518181552" -i '%Y%m%d%H%M%S' -f %s000

@mailsanchu
Copy link
Author

That is good enough for me Closing the ticket Thank you

@mailsanchu
Copy link
Author

Is there a way to convert epoch milliseconds to human readable? Something like 1679930053000

@mailsanchu mailsanchu reopened this Mar 27, 2023
@hroptatyr
Copy link
Owner

Afraid not. The parser trick above doesn't even work because of ambiguity (it's unclear where %s ends and the milliseconds are supposed to start). The only way is to convert the timestamp to epoch time somehow. E.g. if the value is in a shell variable

$ x=1679930053000
$ dateconv @${x%???}

or if it comes on stdin, plug an awk in between:

$ echo 1679930053000 | awk '$0=substr($0,1,length($0)-3)' | dateconv -i %s

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants