zoukankan      html  css  js  c++  java
  • JTimeUtils

    import java.math.BigDecimal;
    import java.text.ParseException;
    import java.util.Calendar;
    import java.util.GregorianCalendar;
    
    import javax.annotation.Resource;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    import org.apache.commons.lang3.time.FastDateFormat;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.beans.factory.config.ConfigurableBeanFactory;
    import org.springframework.context.annotation.Scope;
    import org.springframework.web.bind.annotation.RestController;
    
    import com.google.common.collect.Lists; 
    
    @RestController
    @Scope(ConfigurableBeanFactory.SCOPE_SINGLETON)
    public abstract class JTimeUtils { 
    protected FastDateFormat format = FastDateFormat.getInstance("yyyy-MM-dd"); /** * 验证时间是否过了3个月 * * @param time * @return */ public boolean validateTime(String time) { try { threadLocal.get().setTime(format.parse(time)); threadLocal.get().add(Calendar.MONTH, 3 + 1); return (threadLocal.get().getTime().getTime() >= System.currentTimeMillis()); } catch (ParseException e) { e.printStackTrace(); } return false; } /** * 四舍五入保留1位小数 * * @param val * @return */ public double toDouble(double val) { BigDecimal bigDe = new BigDecimal(val); return bigDe.setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue(); } /** * 要在高并发环境下能有比较好的体验, 可以使用ThreadLocal来限制GregorianCalendar只能在线程内共享, * 这样就避免了多线程导致的线程安全问题。 */ protected static ThreadLocal<GregorianCalendar> threadLocal = new ThreadLocal<GregorianCalendar>() { @Override protected GregorianCalendar initialValue() { return new GregorianCalendar(); } }; }
  • 相关阅读:
    ios -为什么用WKWebView加载相同的html文本,有时展示的内容却不一样。
    weex
    [Objective-C 面试简要笔记]
    [iOS 基于CoreBluetooth的蓝牙4.0通讯]
    [SVN Mac自带SVN结合新浪SAE进行代码管理]
    [SVN Mac的SVN使用]
    [iOS dispatch_once创建单例]
    [iOS UI设计笔记整理汇总]
    [iOS 视频流开发-获得视频帧处理]
    [iOS OpenCV错误解决]
  • 原文地址:https://www.cnblogs.com/light-zhang/p/8821855.html
Copyright © 2011-2022 走看看