How to have Maven show local timezone in maven.build.timestamp?

As already mentioned, in the current versions of Maven (at least up to version 3.3.+), the maven.build.timestamp property does not allow for timezone overrides.

However, if you are okay with utilizing a different property name for your purposes, the build-helper-maven-plugin allows you to configure custom timestamps for a variety of purposes. Here is an example to configure the current timestamp in EST during a build.

        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>build-helper-maven-plugin</artifactId>
            <version>1.10</version>
            <executions>
                <execution>
                    <id>timestamp-property</id>
                    <goals>
                        <goal>timestamp-property</goal>
                    </goals>
                    <configuration>
                        <name>build.time</name>
                        <pattern>MM/dd/yyyy hh:mm aa</pattern>
                        <locale>en_US</locale>
                        <timeZone>America/Detroit</timeZone>
                    </configuration>
                </execution>
            </executions>
        </plugin>

Then you can utilize the ${build.time} property instead of ${maven.build.timestamp} where you need a timestamp of the build in your preferred timezone.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)