<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Get Time in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/get-time/m-p/5044119#M48480</link>
    <description>&lt;!--!*#--&gt;Guys, don't know how much this helps, but chancing upon this page (&lt;A href="http://www.tummy.com/journals/entries/jafo_20070214_155842)," target="_blank"&gt;http://www.tummy.com/journals/entries/jafo_20070214_155842),&lt;/A&gt; i just wrote up a script that gets time of a different timezone/city given either city name or timezone name.&lt;BR /&gt;&lt;BR /&gt;Here's the script - feel free to give your feedback on this. Tested only on linux as of now.&lt;BR /&gt;&lt;BR /&gt;&amp;gt;&amp;gt;&lt;BR /&gt;[ramd@nt14115 ramd]$ cat time.sh&lt;BR /&gt;#!/bin/bash&lt;BR /&gt;&lt;BR /&gt;ZDUMP=/usr/sbin/zdump&lt;BR /&gt;&lt;BR /&gt;if [[ $# = 0 ]]; then&lt;BR /&gt;        echo "Error: $0 &lt;CITY&gt;"&lt;BR /&gt;        exit 1&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;city=$1&lt;BR /&gt;&lt;BR /&gt;if [[ -n $city ]]; then&lt;BR /&gt;        tzfiles=$(find /usr/share/zoneinfo | grep -i $city)&lt;BR /&gt;        if [[ -n ${tzfiles} ]]; then&lt;BR /&gt;                for tzfile in ${tzfiles}&lt;BR /&gt;                do&lt;BR /&gt;                        ${ZDUMP} ${tzfile}&lt;BR /&gt;                done&lt;BR /&gt;        fi&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;exit 0&lt;BR /&gt;[ramd@nt14115 ramd]$&lt;BR /&gt;&amp;lt;&amp;lt;&lt;BR /&gt;&lt;BR /&gt;Run as follows -&lt;BR /&gt;&amp;gt;&amp;gt;&lt;BR /&gt;[ramd@nt14115 ramd]$ ./time.sh&lt;BR /&gt;Error: ./time.sh &lt;CITY&gt;&lt;BR /&gt;[ramd@nt14115 ramd]$ ./time.sh Sara&lt;BR /&gt;/usr/share/zoneinfo/Europe/Sarajevo  Thu May  3 09:25:26 2007 CEST&lt;BR /&gt;/usr/share/zoneinfo/posix/Europe/Sarajevo  Thu May  3 09:25:26 2007 CEST&lt;BR /&gt;/usr/share/zoneinfo/right/Europe/Sarajevo  Thu May  3 09:25:04 2007 CEST&lt;BR /&gt;[ramd@nt14115 ramd]$&lt;BR /&gt;&amp;lt;&amp;lt;&lt;BR /&gt;&lt;BR /&gt;Hope this helps.&lt;BR /&gt;&lt;BR /&gt;- ramd.&lt;/CITY&gt;&lt;/CITY&gt;</description>
    <pubDate>Thu, 03 May 2007 02:39:19 GMT</pubDate>
    <dc:creator>Ramkumar Devanathan</dc:creator>
    <dc:date>2007-05-03T02:39:19Z</dc:date>
    <item>
      <title>Get Time</title>
      <link>https://community.hpe.com/t5/operating-system-linux/get-time/m-p/5044119#M48480</link>
      <description>&lt;!--!*#--&gt;Guys, don't know how much this helps, but chancing upon this page (&lt;A href="http://www.tummy.com/journals/entries/jafo_20070214_155842)," target="_blank"&gt;http://www.tummy.com/journals/entries/jafo_20070214_155842),&lt;/A&gt; i just wrote up a script that gets time of a different timezone/city given either city name or timezone name.&lt;BR /&gt;&lt;BR /&gt;Here's the script - feel free to give your feedback on this. Tested only on linux as of now.&lt;BR /&gt;&lt;BR /&gt;&amp;gt;&amp;gt;&lt;BR /&gt;[ramd@nt14115 ramd]$ cat time.sh&lt;BR /&gt;#!/bin/bash&lt;BR /&gt;&lt;BR /&gt;ZDUMP=/usr/sbin/zdump&lt;BR /&gt;&lt;BR /&gt;if [[ $# = 0 ]]; then&lt;BR /&gt;        echo "Error: $0 &lt;CITY&gt;"&lt;BR /&gt;        exit 1&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;city=$1&lt;BR /&gt;&lt;BR /&gt;if [[ -n $city ]]; then&lt;BR /&gt;        tzfiles=$(find /usr/share/zoneinfo | grep -i $city)&lt;BR /&gt;        if [[ -n ${tzfiles} ]]; then&lt;BR /&gt;                for tzfile in ${tzfiles}&lt;BR /&gt;                do&lt;BR /&gt;                        ${ZDUMP} ${tzfile}&lt;BR /&gt;                done&lt;BR /&gt;        fi&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;exit 0&lt;BR /&gt;[ramd@nt14115 ramd]$&lt;BR /&gt;&amp;lt;&amp;lt;&lt;BR /&gt;&lt;BR /&gt;Run as follows -&lt;BR /&gt;&amp;gt;&amp;gt;&lt;BR /&gt;[ramd@nt14115 ramd]$ ./time.sh&lt;BR /&gt;Error: ./time.sh &lt;CITY&gt;&lt;BR /&gt;[ramd@nt14115 ramd]$ ./time.sh Sara&lt;BR /&gt;/usr/share/zoneinfo/Europe/Sarajevo  Thu May  3 09:25:26 2007 CEST&lt;BR /&gt;/usr/share/zoneinfo/posix/Europe/Sarajevo  Thu May  3 09:25:26 2007 CEST&lt;BR /&gt;/usr/share/zoneinfo/right/Europe/Sarajevo  Thu May  3 09:25:04 2007 CEST&lt;BR /&gt;[ramd@nt14115 ramd]$&lt;BR /&gt;&amp;lt;&amp;lt;&lt;BR /&gt;&lt;BR /&gt;Hope this helps.&lt;BR /&gt;&lt;BR /&gt;- ramd.&lt;/CITY&gt;&lt;/CITY&gt;</description>
      <pubDate>Thu, 03 May 2007 02:39:19 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/get-time/m-p/5044119#M48480</guid>
      <dc:creator>Ramkumar Devanathan</dc:creator>
      <dc:date>2007-05-03T02:39:19Z</dc:date>
    </item>
    <item>
      <title>Re: Get Time</title>
      <link>https://community.hpe.com/t5/operating-system-linux/get-time/m-p/5044120#M48481</link>
      <description>I think that you should post it here - &lt;A href="http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=51050" target="_blank"&gt;http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=51050&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;regards,&lt;BR /&gt;ivan</description>
      <pubDate>Thu, 03 May 2007 03:31:42 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/get-time/m-p/5044120#M48481</guid>
      <dc:creator>Ivan Krastev</dc:creator>
      <dc:date>2007-05-03T03:31:42Z</dc:date>
    </item>
    <item>
      <title>Re: Get Time</title>
      <link>https://community.hpe.com/t5/operating-system-linux/get-time/m-p/5044121#M48482</link>
      <description>Sorry, but it looks like you're reinventing the wheel. Consider this:&lt;BR /&gt;&lt;BR /&gt;$ zdump Europe/Stockholm&lt;BR /&gt;Europe/Stockholm  Thu May  3 10:22:35 2007 CEST&lt;BR /&gt;&lt;BR /&gt;$ TZ=Europe/Stockholm date&lt;BR /&gt;Thu May  3 10:22:47 CEST 2007&lt;BR /&gt;&lt;BR /&gt;So, you don't need to use zdump. With "date", you can use format strings to get the date in exactly the way you like, so it's more flexible to use "date".&lt;BR /&gt;&lt;BR /&gt;If I needed a script like this, the essential functionality would be something like:&lt;BR /&gt;&lt;BR /&gt;timezone="$1"&lt;BR /&gt;shift&lt;BR /&gt;echo -n "${timezone} "&lt;BR /&gt;TZ=${timezone} date "$@"&lt;BR /&gt;&lt;BR /&gt;If a check for timezone's existence is required, that could be done by digging around /usr/share/zoneinfo as in your script.&lt;BR /&gt;&lt;BR /&gt;The TZ environment variable is not "special" or "holy" in any way. If you're in a different timezone from the server you're using or you need to use a different timezone for some other reason, you can override the default with the TZ variable. Just remember that things like crontab always use the system-wide default timezone.&lt;BR /&gt;&lt;BR /&gt;In Linux (and some other unixes), there is a way for the sysadmin to choose a default timezone which is automatically used if TZ is unset; in other unixes, the TZ variable is the primary way of setting the timezone.&lt;BR /&gt;&lt;BR /&gt;If the unix variant you're using has time zones specified as "continent/capital", it usually understands that format in the TZ variable too. Other unixes will understand only "CET-1CEST" style TZ values.&lt;BR /&gt;&lt;BR /&gt;In your link, the writer of the webpage was not interested in the current time, but the past and future times of standard &amp;lt;-&amp;gt; DST time transitions. This requires the use of zdump.&lt;BR /&gt;&lt;BR /&gt;MK</description>
      <pubDate>Thu, 03 May 2007 03:52:19 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/get-time/m-p/5044121#M48482</guid>
      <dc:creator>Matti_Kurkela</dc:creator>
      <dc:date>2007-05-03T03:52:19Z</dc:date>
    </item>
    <item>
      <title>Re: Get Time</title>
      <link>https://community.hpe.com/t5/operating-system-linux/get-time/m-p/5044122#M48483</link>
      <description>Guys, thanks for all the inputs.&lt;BR /&gt;&lt;BR /&gt;I didn't really mean to re-invent the wheel, and in the script all I do is to reduce the effort for the user to search for a city name within /usr/share/zoneinfo/... and print current time of that city/tz.&lt;BR /&gt;&lt;BR /&gt;MK, really value your inputs. Thanks.&lt;BR /&gt;&lt;BR /&gt;Ivan, i would not venture to post this yet in the other thread - maybe after i make the changes that MK suggests. But thanks for the idea.&lt;BR /&gt;&lt;BR /&gt;- ramd.&lt;BR /&gt;'Learning more everyday.'</description>
      <pubDate>Sat, 05 May 2007 01:28:24 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/get-time/m-p/5044122#M48483</guid>
      <dc:creator>Ramkumar Devanathan</dc:creator>
      <dc:date>2007-05-05T01:28:24Z</dc:date>
    </item>
    <item>
      <title>Re: Get Time</title>
      <link>https://community.hpe.com/t5/operating-system-linux/get-time/m-p/5044123#M48484</link>
      <description>Thanks for all the inputs.</description>
      <pubDate>Thu, 09 Apr 2009 21:44:43 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/get-time/m-p/5044123#M48484</guid>
      <dc:creator>Ramkumar Devanathan</dc:creator>
      <dc:date>2009-04-09T21:44:43Z</dc:date>
    </item>
  </channel>
</rss>

