时间戳中的 Maven 时间构建 属性
maven time build property in timestamp
我正在使用 Maven 的 属性 来获取项目构建时间。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
<webResources>
<resource>
<directory>${basedir}/src/main/webapp/WEB-INF</directory>
<filtering>true</filtering>
<targetPath>WEB-INF</targetPath>
<includes>
<include>**/web.xml</include>
</includes>
</resource>
</webResources>
</configuration>
</plugin>
<properties>
<timestamp>${maven.build.timestamp}</timestamp>
<maven.build.timestamp.format>yyyy--mm-dd hh-mm</maven.build.timestamp.format>
</properties>
然后我可以像这样在我的 jsp 页面上获取它
${initParam.buildTimeStamp}
但我想知道有没有一种方法可以获取时间戳格式的时间。例如,如果构建时间是 2015-01-17 10-23-57 那么在时间戳中它应该看起来像 1421490237
But i'm wondering is there a way how to get time in timestamp format
Maven 文档指出:
The format pattern has to comply with the rules given in the API
documentation for SimpleDateFormat.
https://maven.apache.org/guides/introduction/introduction-to-the-pom.html
并且 SimpleDateFormat API 文档没有提到任何获取原始 "milliseconds-since-epoch" 格式的方法。
所以,我认为使用内置的 Maven 构建时间戳是不可能的。
但是,在您的 JSP 中,您可以使用 SimpleDateFormat 解析日期 - 这将为您提供一个 Date 对象,然后您可以从中提取这个 long 值。
我正在使用 Maven 的 属性 来获取项目构建时间。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
<webResources>
<resource>
<directory>${basedir}/src/main/webapp/WEB-INF</directory>
<filtering>true</filtering>
<targetPath>WEB-INF</targetPath>
<includes>
<include>**/web.xml</include>
</includes>
</resource>
</webResources>
</configuration>
</plugin>
<properties>
<timestamp>${maven.build.timestamp}</timestamp>
<maven.build.timestamp.format>yyyy--mm-dd hh-mm</maven.build.timestamp.format>
</properties>
然后我可以像这样在我的 jsp 页面上获取它
${initParam.buildTimeStamp}
但我想知道有没有一种方法可以获取时间戳格式的时间。例如,如果构建时间是 2015-01-17 10-23-57 那么在时间戳中它应该看起来像 1421490237
But i'm wondering is there a way how to get time in timestamp format
Maven 文档指出:
The format pattern has to comply with the rules given in the API documentation for SimpleDateFormat. https://maven.apache.org/guides/introduction/introduction-to-the-pom.html
并且 SimpleDateFormat API 文档没有提到任何获取原始 "milliseconds-since-epoch" 格式的方法。
所以,我认为使用内置的 Maven 构建时间戳是不可能的。 但是,在您的 JSP 中,您可以使用 SimpleDateFormat 解析日期 - 这将为您提供一个 Date 对象,然后您可以从中提取这个 long 值。