zsh-users
 help / color / mirror / code / Atom feed
From: TJ Luoma <luomat@gmail.com>
To: Zsh-Users List <zsh-users@zsh.org>
Subject: Convert UTC time to local time using strftime and zsh/datetime
Date: Fri, 20 Feb 2015 23:41:24 -0500	[thread overview]
Message-ID: <CADjGqHvaOkB-T_qGHDvt9=8TzSGiR8-FptXCX8VNFyfPkmJN-g@mail.gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 1325 bytes --]

I have a screenshot of my iPhone which shows that it was taken at 11:42 a.m.

When I look at the file in Finder, it shows that it was taken at 11:42 a.m.
on Feb 11

You can see a screenshot here:
http://images.luo.ma/skitch/iPhonePhotos-1142am-20150220-231455.jpg

When I use `mdls -raw -name kMDItemContentCreationDate test.png` (a Mac
command to get the Creation Date), I get

2015-02-11 16:42:30 +0000

as the answer. This is, I believe, UTC. So I need to convert that to local
(US/Eastern) time.

I'm not sure how to do that, so heres what I did

1) Load the appropriate module

> zmodload zsh/datetime

2) get the Unix EPOCH time from the date/time stamp we have:

> strftime -r "%Y-%m-%d %H:%M:%S +0000" "2015-02-11 16:42:30 +0000"
1423690950

3) Convert '1423690950' to US/Eastern time:

> strftime "%Y-%m-%d %H:%M:%S" "1423690950"
2015-02-11 16:42:30

But that's still giving me '16' as the hour. It should be 11, shouldn't it?

4) Try again, this time making sure that I define the time zone:

> TZ=US/Eastern strftime "%Y-%m-%d %H:%M:%S" "1423690950"
2015-02-11 16:42:30

Same time.

OK, so I'm obviously missing something. I checked '1423690950' on various
online "Unix time" converters and they confirm that it's 16:42 my time, but
since I know the picture was taken at 11:42, I'm wondering what I did wrong.

Tj

             reply	other threads:[~2015-02-21  4:42 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-21  4:41 TJ Luoma [this message]
2015-02-21  5:02 ` Kurtis Rader
2015-02-21 18:23   ` Bart Schaefer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CADjGqHvaOkB-T_qGHDvt9=8TzSGiR8-FptXCX8VNFyfPkmJN-g@mail.gmail.com' \
    --to=luomat@gmail.com \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).