Want more features on Pastebin? Sign Up, it's FREE!
Guest

new Date() Optimization

By: a guest on Jun 12th, 2013  |  syntax: Java  |  size: 0.29 KB  |  views: 22  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
This paste has a previous version, view the difference. Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1.     private Date now;
  2.     private long nowLastUpdate;
  3.    
  4.     private Date getNow() {
  5.         long nowMillis = System.currentTimeMillis();
  6.         if (now == null || nowMillis - nowLastUpdate >= 60 * 1000) {
  7.                 now = new Date();
  8.                 nowLastUpdate = nowMillis;
  9.         }
  10.         return now;
  11.     }
clone this paste RAW Paste Data