{"id":2068,"date":"2012-03-28T08:52:20","date_gmt":"2012-03-28T13:52:20","guid":{"rendered":"http:\/\/appcrawler.com\/wordpress\/?p=2068"},"modified":"2012-04-09T21:57:38","modified_gmt":"2012-04-10T02:57:38","slug":"java-date-difference-in-milliseconds","status":"publish","type":"post","link":"http:\/\/appcrawler.com\/wordpress\/2012\/03\/28\/java-date-difference-in-milliseconds\/","title":{"rendered":"Java date difference in milliseconds"},"content":{"rendered":"<p>Every time I need to do math on a date in java, I end up googling it.  While that isn&#8217;t the worst way to do things (hey, it&#8217;s probably how you found this :)), I wanted something I *knew* would be there.  I know there are libraries out there for this, but I usually want something very simple like, &#8220;run this in a loop for 60 seconds&#8221;.  Here is what I use&#8230;<\/p>\n<pre lang=\"java\" line=\"1\">\r\nlong START_TIME = new java.util.Date().getTime();\r\nwhile (new java.util.Date().getTime() - START_TIME < 60000) {\r\n  \/\/do something\r\n}\r\n<\/pre>\n<p>I don't know how efficient the getTime() method is, but this works.  You could also use System.currentTimeMillis()...<\/p>\n<pre lang=\"java\" line=\"1\">\r\nlong START_TIME = new java.util.Date().getTime();\r\nwhile (System.currentTimeMillis() - START_TIME < 60000) {\r\n  \/\/do something\r\n}\r\n<\/pre>\n<p>My guess is this is more efficient.  One of these days I will test it.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Every time I need to do math on a date in java, I end up googling it. While that isn&#8217;t the worst way to do things (hey, it&#8217;s probably how you found this :)), I wanted something I *knew* would&hellip;<\/p>\n<p class=\"more-link-p\"><a class=\"more-link\" href=\"http:\/\/appcrawler.com\/wordpress\/2012\/03\/28\/java-date-difference-in-milliseconds\/\">Read more &rarr;<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"footnotes":""},"categories":[24,25],"tags":[],"_links":{"self":[{"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts\/2068"}],"collection":[{"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/comments?post=2068"}],"version-history":[{"count":6,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts\/2068\/revisions"}],"predecessor-version":[{"id":2125,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts\/2068\/revisions\/2125"}],"wp:attachment":[{"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/media?parent=2068"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/categories?post=2068"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/tags?post=2068"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}