forked from matomo-org/matomo-java-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPiwikDate.java
More file actions
62 lines (56 loc) · 1.79 KB
/
PiwikDate.java
File metadata and controls
62 lines (56 loc) · 1.79 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*
* Piwik Java Tracker
*
* @link https://github.com/piwik/piwik-java-tracker
* @license https://github.com/piwik/piwik-java-tracker/blob/master/LICENSE BSD-3 Clause
*/
package org.piwik.java.tracking;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;
/**
* A datetime object that will return the datetime in the format {@code yyyy-MM-dd hh:mm:ss}.
*
* @author brettcsorba
*/
public class PiwikDate extends Date{
SimpleDateFormat format;
/**
* Allocates a Date object and initializes it so that it represents the time
* at which it was allocated, measured to the nearest millisecond.
*/
public PiwikDate(){
super();
format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
format.setTimeZone(TimeZone.getTimeZone("UTC"));
}
/**
* Allocates a Date object and initializes it to represent the specified number
* of milliseconds since the standard base time known as "the epoch", namely
* January 1, 1970, 00:00:00 GMT.
* @param date the milliseconds since January 1, 1970, 00:00:00 GMT.
*/
public PiwikDate(long date){
super(date);
format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
format.setTimeZone(TimeZone.getTimeZone("UTC"));
}
/**
* Sets the time zone of the String that will be returned by {@link toString()}.
* Defaults to UTC.
* @param zone the TimeZone to set
*/
public void setTimeZone(TimeZone zone){
format.setTimeZone(zone);
}
/**
* Converts this PiwikDate object to a String of the form:<br>
* <br>
* {@code yyyy-MM-dd hh:mm:ss}.
* @return a string representation of this PiwikDate
*/
@Override
public String toString(){
return format.format(this);
}
}