2 * Copyright (C) 2008 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package com.android.locationtracker.data;
19 import java.util.Calendar;
20 import java.util.TimeZone;
23 * Provides formatting date as string utilities
25 public class DateUtils {
32 * Returns timestamp given by param in KML format ie yyyy-mm-ddThh:mm:ssZ,
33 * where T is the separator between the date and the time and the time zone
36 * @return KML timestamp as String
38 public static String getKMLTimestamp(long when) {
39 TimeZone tz = TimeZone.getTimeZone("GMT");
40 Calendar c = Calendar.getInstance(tz);
41 c.setTimeInMillis(when);
42 return String.format("%tY-%tm-%tdT%tH:%tM:%tSZ", c, c, c, c, c, c);
46 * Helper version of getKMLTimestamp, that returns timestamp for current
49 public static String getCurrentKMLTimestamp() {
50 return getKMLTimestamp(System.currentTimeMillis());
54 * Returns timestamp in following format: yyyy-mm-dd-hh-mm-ss
56 public static String getCurrentTimestamp() {
57 Calendar c = Calendar.getInstance();
58 c.setTimeInMillis(System.currentTimeMillis());
59 return String.format("%tY-%tm-%td-%tH-%tM-%tS", c, c, c, c, c, c);