Updating time offset with moment().utcOffset()

The main issue is that you are passing the offset as a string instead of a number. moment.utc(“2015-10-01 01:24:21”).utcOffset(“-240”).format(‘YYYYMMDD HHmmss ZZ’) // “20151001 012421 +0000” moment.utc(“2015-10-01 01:24:21”).utcOffset(-240).format(‘YYYYMMDD HHmmss ZZ’) // “20150930 212421 -0400” When you have an offset in terms of minutes, then you must use the numeric form. You can always convert it: moment.utc(“2015-10-01 … Read more

Calculate days, hours and minutes between two instants

To calculate days, hours and/or minutes between two Instant objects: Instant instant1 = Instant.parse(“2019-02-14T18:42:00Z”); Instant instant2 = Instant.parse(“2019-04-21T05:25:00Z”); // If you only need one of them System.out.println(ChronoUnit.DAYS.between(instant1, instant2)); // prints: 65 System.out.println(ChronoUnit.HOURS.between(instant1, instant2)); // prints: 1570 System.out.println(ChronoUnit.MINUTES.between(instant1, instant2)); // prints: 94243 // Or use alternate syntax (it’s the same thing) System.out.println(instant1.until(instant2, ChronoUnit.DAYS)); // prints: 65 … Read more

In python, how to check if a date is valid?

You could try doing import datetime datetime.datetime(year=year,month=month,day=day,hour=hour) that will eliminate somethings like months >12 , hours > 23, non-existent leapdays (month=2 has max of 28 on non leap years, 29 otherwise, other months have max of 30 or 31 days)(throws ValueError exception on error) Also you could try to compare it with some sanity upper/lower … Read more

Java 8 Instant.now() with nanosecond resolution?

You can consider yourself lucky if you get even millisecond resolution. Instant may model the time to nanosecond precision, but as for the actual resolution, it depends on the underlying OS implementation. On Windows, for example, the resolution is pretty low, on the order of 10 ms. Compare this with System.nanoTime(), which gives resolution in … Read more

How to set a maximum execution time for a mysql query?

I thought it has been around a little longer, but according to this, MySQL 5.7.4 introduces the ability to set server side execution time limits, specified in milliseconds, for top level read-only SELECT statements. SELECT /*+ MAX_EXECUTION_TIME(1000) */ –in milliseconds * FROM table; Note that this only works for read-only SELECT statements. Update: This variable … Read more

How to tell .hover() to wait?

This will make the second function wait 2 seconds (2000 milliseconds) before executing: $(‘.icon’).hover(function() { clearTimeout($(this).data(‘timeout’)); $(‘li.icon > ul’).slideDown(‘fast’); }, function() { var t = setTimeout(function() { $(‘li.icon > ul’).slideUp(‘fast’); }, 2000); $(this).data(‘timeout’, t); }); It also clears the timeout when the user hovers back in to avoid crazy behavior. This is not a very … Read more