Просмотр исходного кода

Simple util to build Dates from Strings

peter_backlund 18 лет назад
Родитель
Сommit
24b8077830
1 измененных файлов: 25 добавлений и 0 удалений
  1. 25
    0
      dddsample/src/test/java/se/citerus/dddsample/DateTestUtil.java

+ 25
- 0
dddsample/src/test/java/se/citerus/dddsample/DateTestUtil.java Просмотреть файл

@@ -0,0 +1,25 @@
1
+package se.citerus.dddsample;
2
+
3
+import java.text.ParseException;
4
+import java.text.SimpleDateFormat;
5
+import java.util.Date;
6
+
7
+/**
8
+ * A few utils for working with Date in tests.
9
+ *
10
+ */
11
+public class DateTestUtil {
12
+
13
+  public static Date toDate(String date) {
14
+    return toDate(date, "00:00.00.000");
15
+  }
16
+
17
+  public static Date toDate(String date, String time) {
18
+    try {
19
+      return new SimpleDateFormat("yyyy-MM-dd hh:mm").parse(date + " " + time);
20
+    } catch (ParseException e) {
21
+      throw new RuntimeException(e);
22
+    }
23
+  }
24
+
25
+}