1 package cn.home1.oss.lib.common;
2
3 import static org.joda.time.format.DateTimeFormat.forPattern;
4
5 import org.joda.time.DateTime;
6 import org.joda.time.DateTimeZone;
7 import org.joda.time.Minutes;
8 import org.joda.time.format.DateTimeFormat;
9 import org.joda.time.format.DateTimeFormatter;
10
11 import java.nio.charset.Charset;
12
13
14
15
16 public abstract class Defaults {
17
18 private Defaults() {
19 }
20
21 public static final Charset UTF_8 = Charset.forName("UTF-8");
22
23 public static final String CRON_EVERY_30_SECONDS = "0/30 * * * * ?";
24
25 public static final DateTimeZone UTC_P8 = DateTimeZone.forID("Asia/Shanghai");
26
27 public static final DateTime EPOCH = new DateTime(0L);
28
29 public static final DateTimeFormatter yyyyMMdd_HHmmss;
30 public static final DateTimeFormatter ISO8601;
31
32 public static DateTime now() {
33 return DateTime.now(UTC_P8);
34 }
35
36 public static Integer minutesSinceEpoch(final DateTime dateTime) {
37 return Minutes.minutesBetween(EPOCH, dateTime).getMinutes();
38 }
39
40
41
42
43
44
45
46 public static final String PATTERN_JAVA_ISO8601 = "yyyy-MM-dd'T'HH:mm:ss.SSSXXX";
47 public static final String PATTERN_JODA_ISO8601 = "yyyy-MM-dd'T'HH:mm:ss.SSSZZ";
48
49 static {
50 yyyyMMdd_HHmmss = forPattern("yyyyMMdd-HH:mm:ss").withZone(UTC_P8);
51 ISO8601 = DateTimeFormat.forPattern(PATTERN_JODA_ISO8601).withZone(UTC_P8);
52 }
53 }