comparison software/mpdl-services/mpiwg-mpdl-xml/src/de/mpg/mpiwg/berlin/mpdl/util/Util.java @ 23:e845310098ba

diverse Korrekturen
author Josef Willenborg <jwillenborg@mpiwg-berlin.mpg.de>
date Tue, 27 Nov 2012 12:35:19 +0100
parents dc5e9fcb3fdc
children
comparison
equal deleted inserted replaced
22:6a45a982c333 23:e845310098ba
1 package de.mpg.mpiwg.berlin.mpdl.util; 1 package de.mpg.mpiwg.berlin.mpdl.util;
2 2
3 import java.io.File; 3 import java.io.File;
4 import java.io.FileInputStream; 4 import java.io.FileInputStream;
5 import java.io.IOException; 5 import java.io.IOException;
6 import java.text.DateFormat;
7 import java.text.ParseException;
8 import java.text.SimpleDateFormat;
9 import java.util.Date;
6 import java.util.Properties; 10 import java.util.Properties;
11
12 import de.mpg.mpiwg.berlin.mpdl.exception.ApplicationException;
7 13
8 public class Util { 14 public class Util {
9 15
10 public Properties getProperties(String fullFileName) { 16 public Properties getProperties(String fullFileName) {
11 Properties props = new Properties(); 17 Properties props = new Properties();
12 try { 18 try {
13 File file = new File(fullFileName); 19 File file = new File(fullFileName);
14 FileInputStream in = new FileInputStream(file); 20 FileInputStream in = new FileInputStream(file);
15 props.load(in); 21 props.load(in);
16 } catch (IOException e) { 22 } catch (IOException e) {
23 e.printStackTrace();
17 } 24 }
18 return props; 25 return props;
19 } 26 }
27
28 public String toYearStr(String inputStr) {
29 String retYearStr = inputStr.trim();
30 int index = inputStr.indexOf("-");
31 if (index > 0) {
32 retYearStr = inputStr.substring(0, index);
33 retYearStr = retYearStr.trim();
34 }
35 return retYearStr;
36 }
37
38 public Date toDate(String xsDateStr) throws ApplicationException {
39 Date retDate = null;
40 if (xsDateStr == null)
41 return null;
42 try {
43 DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
44 retDate = dateFormat.parse(xsDateStr);
45 } catch (ParseException e) {
46 throw new ApplicationException(e);
47 }
48 return retDate;
49 }
50
51 public String toXsDate(Date date) {
52 DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
53 String xsDateStr = dateFormat.format(date);
54 return xsDateStr;
55 }
20 56
57 public Double getSecondWithMillisecondsBetween(Date begin, Date end) {
58 long beginMS = begin.getTime();
59 long endMS = end.getTime();
60 long elapsedSeconds = (endMS - beginMS) / 1000;
61 long elapsedMilliSecondsAfterSeconds1 = (endMS - beginMS) - (elapsedSeconds * 1000);
62 Double seconds = new Double(elapsedSeconds + "." + elapsedMilliSecondsAfterSeconds1);
63 return seconds;
64 }
65
21 } 66 }