Java Timestamp Convert To timestampToPrettyString(long ts)

Here you can find the source of timestampToPrettyString(long ts)

Description

Format ts from "0m00" to "59m59", then "1h00" to "xxxxh59"

License

Open Source License

Parameter

Parameter Description
ts a parameter

Declaration

public static String timestampToPrettyString(long ts) 

Method Source Code

//package com.java2s;
/*//w  ww . j  a  v  a 2s.  c  o  m
 * Copyright (c) 2001-2011 Convertigo SA.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Affero General Public License
 * as published by the Free Software Foundation; either version 3
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, see<http://www.gnu.org/licenses/>.
 *
 * $URL$
 * $Author$
 * $Revision$
 * $Date$
 */

public class Main {
    /**
     * Format ts from "0m00" to "59m59", then "1h00" to "xxxxh59"
     * 
     * @param ts
     * @return
     */
    public static String timestampToPrettyString(long ts) {
        long s = (ts /= 1000) % 60;
        long m = (ts /= 60) % 60;
        long h = ts / 60;
        return (h > 0 ? (h + "h") : "") + ((m < 10 && h > 0) ? "0" : "") + m
                + (h == 0 ? ("m" + ((s < 10) ? "0" : "") + s) : "");
    }
}

Related

  1. timestampToDayNumber(long timestamp)
  2. timestampToInternal(java.sql.Timestamp ts)
  3. timestampToLong(Timestamp ts)
  4. timestampToMicros(Timestamp timestamp)
  5. timestampToParts(long time)
  6. timestampToSearchString(final Timestamp timestamp)
  7. timestampToString(long time)
  8. timestampToTicks(int year, int month, int day, int hours, int minutes, int seconds, int milliseconds)
  9. to_timestamp(String date)