JP Vossen on 15 Oct 2018 10:46:07 -0700


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: [PLUG] date format


On 10/15/2018 12:24 PM, jeff wrote:
I have lots of backups from my old phone, so naturally none of the calendar backups work. I finally resigned myself to manual input, but even that didn't work.

1507075200000 is somehow 10/4/yyyy. Every date is like this.
It won't format to date, even chucking the leading 1 and/or trailing zeroes. It's almost like it's personal with these phones.

Has anybody seen this before?

As Jason pointed out that's an Epoch. Here's something I wrote last month for someone at $WORK with a similar need. It's quite ugly brute-force, but...it works.

----
#!/bin/bash -
# 2018-09-12: trivial Epoch converter wrapper

echo "$1" | \
  perl -ne 'use POSIX qw(strftime);
    print "$1 = " ,
      strftime("%Y-%m-%d %H:%M:%S %z\n", gmtime($1))
        if m/^(\d{10}).*$/;'
----

$ ./epoch.sh 1507075200000
1507075200 = 2017-10-04 00:00:00 -0400

Adjust the strftime string (`man date`) as desired and wrap the rest in a loop or something. Or post a sample of the data/file format and I or someone else can tweak to handle it. Python does it cleaner, but I know Perl and Perl does nice one-timers. :-)

Contortions using GNU `date` will work too. Chapter 11 of the _Bash Cookbook_ is devoted to "Working with Dates and Times" and uses a lot of GNU `date`.

Later,
JP
--  -------------------------------------------------------------------
JP Vossen, CISSP | http://www.jpsdomain.org/ | http://bashcookbook.com/
___________________________________________________________________________
Philadelphia Linux Users Group         --        http://www.phillylinux.org
Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce
General Discussion  --   http://lists.phillylinux.org/mailman/listinfo/plug