当前位置: 代码迷 >> 综合 >> Java如何记录程序启动时间?
  详细解决方案

Java如何记录程序启动时间?

热度:60   发布时间:2024-02-06 21:42:18.0

1、使用jre自带的ManagementFactory类获取

java.lang.management.ManagementFactory.getRuntimeMXBean().getStartTime()

2、在WEB监听器/定时器中定义时间戳变量

public class TimerListener implements ServletContextListener {public static final long StartTime = System.currentTimeMillis();@Overridepublic void contextDestroyed(ServletContextEvent arg0) {//xxxx}
}

 

以上方法都为时间戳,需要通过转换成yyyyMM等格式。