Sleuth Kit Java Bindings (JNI)  4.4.1
Java bindings for using The Sleuth Kit
TimeUtilities.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2013-2017 Basis Technology Corp.
5  * Contact: carrier <at> sleuthkit <dot> org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 
20 package org.sleuthkit.datamodel;
21 
22 import java.text.SimpleDateFormat;
23 import java.util.TimeZone;
24 import java.util.logging.Level;
25 import java.util.logging.Logger;
26 
31 public class TimeUtilities {
32  private static final Logger LOGGER = Logger.getLogger(TimeUtilities.class.getName());
33  private static final SimpleDateFormat DATE_FORMATTER = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z");
34 
42  public static String epochToTime(long epoch) {
43  String time = "0000-00-00 00:00:00";
44  if (epoch != 0) {
45  time = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss z").format(new java.util.Date(epoch * 1000));
46  }
47  return time;
48  }
49 
59  public static String epochToTime(long epoch, TimeZone tzone) {
60  String time = "0000-00-00 00:00:00";
61  if (epoch != 0) {
62  synchronized (DATE_FORMATTER) {
63  DATE_FORMATTER.setTimeZone(tzone);
64  time = DATE_FORMATTER.format(new java.util.Date(epoch * 1000));
65  }
66  }
67  return time;
68  }
69 
77  public static long timeToEpoch(String time) {
78  long epoch = 0;
79  try {
80  epoch = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(time).getTime() / 1000;
81  } catch (Exception e) {
82  LOGGER.log(Level.WARNING, "Failed to parse time string", e); //NON-NLS
83  }
84 
85  return epoch;
86  }
87 }
static long timeToEpoch(String time)
static String epochToTime(long epoch)
static final SimpleDateFormat DATE_FORMATTER
static String epochToTime(long epoch, TimeZone tzone)

Copyright © 2011-2015 Brian Carrier. (carrier -at- sleuthkit -dot- org)
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.