TimeUtil { public static long parse(String window) { char c = window.charAt(window.length() - 1); int num = Integer.parseInt(window.substring(0, window.length() - 1)); switch (c) { case 's': return num * 1000; case 'm': return num * 60 * 1000; case 'h': return num * 60 * 60 * 1000; case 'd': return num * 60 * 60 * 24 * 1000; default: throw new RuntimeException("error window format:" + window); } } private  TimeUtil(); static long str2Time(String timeStr); static String timestamp2ISODate(long timestamp); static long parse(String window);  }
@Test public void testparse() { Assert.assertEquals(1000, TimeUtil.parse("1s")); Assert.assertEquals(60000, TimeUtil.parse("1m")); Assert.assertEquals(3600000, TimeUtil.parse("1h")); Assert.assertEquals(86400000, TimeUtil.parse("1d")); }
@Test(expected = RuntimeException.class) public void testparseException() { Assert.assertEquals(86400000, TimeUtil.parse("1w")); }