Friday, November 8, 2013

How to get your phing to print out timestamp within your timezone?

Try to get the phing scripts below to echo the right timestamp but always unable to do so. The printed timestamp always based on the UTC timestamp.

    <tstamp>
        <format pattern="%Y%m%d_%H%M%S" property="build.time">  
    </format></tstamp>

 <target name="tstamp"> 
  <tstamp>
  <echo>build time = ${build.time}</echo> 
 </tstamp></target>
Initially, I thought this was phing issue, put the locale attributes insides 'format pattern="%Y%m%d_%H%M%S" property="build.time" locale="Asia/Singapore"', but it doesn't solve the issue.
Spent quite a long time to find the root cause, finally, got the clue on what was happening.

Open the php.ini that your PHP is referring to, edit the locale as your current timezone. For other timezone, please refer to http://us1.php.net/manual/en/datetime.configuration.php#ini.date.timezone
date.timezone = Asia/Singapore
Rerun your phing with the same piece of code. Voila! it just work like a charm!

No comments: