Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: best way to convert UTC to local time?



On Jun 11, 2013, at 5:51 PM, TJ Luoma <luomat@xxxxxxxxx> wrote:

> This works, but three separate `strftime` calls seems inefficient. I mean, it's not like it takes a long time to run or anything, I'm just wondering if there's a "better" way.

Well, if you're willing to use an external command, you could go with date(1):

    for F in "$@"; do
        [[ -f "$F" && -r "$F"]] || continue
        DATE_ADDED_UTC=$(mdls -raw -name kMDItemDateAdded "$F")
        [[ "$DATE_ADDED_UTC" != "(null)" ]] || continue
        DATE_ADDED_LOCAL=$(date -jf '%F %T %z' "$DATE_ADDED_UTC" '+%F')
        echo "The file $F was added on $DATE_ADDED_LOCAL"
    done

vq


Messages sorted by: Reverse Date, Date, Thread, Author