blob: 138352ca8c83bb7d6cfa0b9a5d15f63825ca26e2 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
/**
*
* Copyright (c) 2011, 2016 - Loetz GmbH&Co.KG (69115 Heidelberg, Germany)
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Christophe Loetz (Loetz GmbH&Co.KG) - initial implementation
*
*/
package org.eclipse.osbp.utils.constants;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.concurrent.TimeUnit;
@SuppressWarnings("serial")
public class ExtendedDate extends Date {
public static Date add(Date base, long span, TimeUnit unit) {
// daylight saving time fix
if (TimeUnit.DAYS.equals(unit)) {
Calendar c = Calendar.getInstance();
c.setTime(base);
c.add(Calendar.DAY_OF_MONTH, (int) span);
return c.getTime();
}
return new Date(base.getTime() + unit.toMillis(span));
}
private static final SimpleDateFormat sDateFormat = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss-SSS");
public static String timeStampToString() {
return timeStampToString(System.currentTimeMillis());
}
public static String timeStampToString(long milli) {
return (milli > 0) ? sDateFormat.format(new Date(milli)) : "";
}
}
|