From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26744 invoked by alias); 21 Feb 2015 05:03:07 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 19882 Received: (qmail 21347 invoked from network); 21 Feb 2015 05:03:05 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,HTML_MESSAGE, RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=d8R+/rl4vD/vuJdhTuDBmx2Qadoly6ZVwk1NQXrESDU=; b=V+ag/PTH4iZqxfilO86DPh4aLARzSGV5/jLMqgs304X74uy5Wn+S7l2H3nJCwIRUWH H+Uz6wpTY9IbL+rwR3AgVet/52wOWhlaBDp3ONxtBYbFb9xLqRPe7J/F68kZp8Oxa7K5 UbYZYr9R9MIlyrbDkVfO0YNzUG7K2goe6Qj0GCGyr2A3arwq5CXp9QFxc4WEwNdKkqCJ 0T/S3Z0JnDcE/HTmf4UHdW/vNvDxL+DWJtQGzE7i7Pp4QcMUXDxxyuM4oZE7bbB6vCGT EGopOj+fkgGKvaA65PopH5HPliX5aVyT6lEWEpD4hn/vyxVY19fKOSzdjDaGP0gjA4hc xMNg== X-Gm-Message-State: ALoCoQlaCkMQBHBOPXhXxz16FH3F8F1u6VntRU3QAcNuGAAK6CfTSgsX3uXq5H+HxId6WEENTcXl MIME-Version: 1.0 X-Received: by 10.152.43.228 with SMTP id z4mr703046lal.111.1424494979582; Fri, 20 Feb 2015 21:02:59 -0800 (PST) In-Reply-To: References: Date: Fri, 20 Feb 2015 21:02:59 -0800 Message-ID: Subject: Re: Convert UTC time to local time using strftime and zsh/datetime From: Kurtis Rader To: TJ Luoma Cc: Zsh-Users List Content-Type: multipart/alternative; boundary=001a11c2280c3e230d050f9215cc --001a11c2280c3e230d050f9215cc Content-Type: text/plain; charset=UTF-8 If you believe the formatted date/time string is in the UTC timezone you need to TZ=UTC strftime -r "%Y-%m-%d %H:%M:%S +0000" "2015-02-11 16:42:30 +0000" Which should yield 1423672950 as the seconds since the UNIX epoch. I use the following Python program to convert seconds since the UNIX epoch to UTC and local time. For example (note that I'm on the west coast of the USA, UTC-8): $ time2str 1423672950 UTC 2015-02-11 16:42:30 Local 2015-02-11 08:42:30 #!/usr/bin/env python2.7 from __future__ import print_function import sys import time TIME_FMT = '%Y-%m-%d %H:%M:%S' seconds_epoch = float(sys.argv[1]) utc = time.gmtime(seconds_epoch) local = time.localtime(seconds_epoch) print('UTC {}'.format(time.strftime(TIME_FMT, utc))) print('Local {}'.format(time.strftime(TIME_FMT, local))) On Fri, Feb 20, 2015 at 8:41 PM, TJ Luoma wrote: > 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 > -- Kurtis Rader Caretaker of the exceptional canines Junior and Hank --001a11c2280c3e230d050f9215cc--