Autopsy  4.19.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
TimeStampUtils.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2015-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 package org.sleuthkit.autopsy.coreutils;
20 
21 import java.text.SimpleDateFormat;
22 import java.util.Calendar;
23 import java.util.regex.Matcher;
24 import java.util.regex.Pattern;
25 
30 public final class TimeStampUtils {
31 
32  /*
33  * Sample time stamp suffix: 2015_02_02_12_10_31
34  */
35  private static final Pattern TIME_STAMP_PATTERN = Pattern.compile("\\d{4}_\\d{2}_\\d{2}_\\d{2}_\\d{2}_\\d{2}$");
36  private static final int LENGTH_OF_DATE_TIME_STAMP = 20; // length of the above time stamp
37  private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss");
38 
46  public static boolean endsWithTimeStamp(String inputString) {
47  Matcher m = TIME_STAMP_PATTERN.matcher(inputString);
48  return m.find();
49  }
50 
56  public static int getTimeStampLength() {
58  }
59 
65  public static String createTimeStamp() {
66  return DATE_FORMAT.format(Calendar.getInstance().getTime());
67  }
68 
76  public static String removeTimeStamp(String inputString) {
77  String trimmedString = inputString;
78  if (inputString != null && endsWithTimeStamp(inputString)) {
79  trimmedString = inputString.substring(0, inputString.length() - getTimeStampLength());
80  }
81  return trimmedString;
82  }
83 
91  public static String getTimeStampOnly(String inputString) {
92  String timeStamp = "";
93  if (inputString != null && endsWithTimeStamp(inputString)) {
94  timeStamp = inputString.substring(inputString.length() - getTimeStampLength(), inputString.length());
95  }
96  return timeStamp;
97  }
98 
99  /*
100  * Private contructor to prevent instantiation.
101  */
102  private TimeStampUtils() {
103  }
104 }
static String getTimeStampOnly(String inputString)
static String removeTimeStamp(String inputString)
static boolean endsWithTimeStamp(String inputString)

Copyright © 2012-2021 Basis Technology. Generated on: Thu Sep 30 2021
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.