zoukankan      html  css  js  c++  java
  • spring boot配置时区

    项目配置时区为中国上海:

    import lombok.extern.slf4j.Slf4j;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    import simple.proj.zxz.play.prop.CommProp;
    
    import javax.annotation.PostConstruct;
    import java.util.TimeZone;
    
    @SpringBootApplication
    @Slf4j
    public class PlayApplication {
    
        @Autowired
        private CommProp commProp;
    
        @PostConstruct
        void started() {
            //时区设置:中国上海
            //time.zone: "Asia/Shanghai"
            TimeZone.setDefault(TimeZone.getTimeZone(commProp.getTimeZone()));
        }
    
        public static void main(String[] args) {
            log.info("*** starting application PLAY ***");
            SpringApplication.run(PlayApplication.class, args);
            log.info("*** application PLAY started ***");
        }
    
    }

    如果想要设置其他时区,可以先查看所有支持的时区设置:

    import first.zxz.tools.PrintTool;
    
    import java.util.TimeZone;
    
    /**
     * 测试类
     *
     * @author zhangxz
     * 2019/11/6
     */
    
    
    public class Test {
    
        public static void main(String[] args) {
            System.out.println("可选得时区总数量:" + TimeZone.getAvailableIDs().length);
            PrintTool.printStringArr(TimeZone.getAvailableIDs());
    //        System.out.println(TimeZone.getTimeZone("Asia/Shanghai"));
    //        System.out.println(TimeZone.getTimeZone("CTT"));
        }
    
    }

    结束

  • 相关阅读:
    小福bbs-冲刺日志(第三天)
    小福bbs-冲刺日志(第二天)
    小福bbs-冲刺日志(第一天)
    灯塔-冲刺集合
    团队作业第六次—事后诸葛亮
    灯塔-冲刺总结
    灯塔-测试总结
    灯塔-冲刺日志(第七天)
    灯塔-冲刺日志(第六天)
    灯塔-冲刺日志(第五天)
  • 原文地址:https://www.cnblogs.com/zhangxuezhi/p/11812493.html
Copyright © 2011-2022 走看看