Java Hour Format formatRuntime(long runtime)

Here you can find the source of formatRuntime(long runtime)

Description

Returns the given runtime formatted as ISO-8601 string.

License

Open Source License

Parameter

Parameter Description
runtime the runtime

Return

the formatted runtime

Declaration

public static synchronized String formatRuntime(long runtime) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2010, 2011 LogSaw project and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:/*from  w w w  .  j av  a2s . com*/
 *    LogSaw project committers - initial API and implementation
 *******************************************************************************/

import java.text.DateFormat;

import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    private static DateFormat runtimeDateFormat = new SimpleDateFormat("D'T'HH:mm:ss");

    /**
     * Returns the given runtime formatted as ISO-8601 string.
     * @param runtime the runtime
     * @return the formatted runtime
     */
    public static synchronized String formatRuntime(long runtime) {
        return decrementDays(runtimeDateFormat.format(new Date(runtime)));
    }

    private static String decrementDays(String str) {
        int idx = str.indexOf('T');
        int days = Integer.parseInt(str.substring(0, idx));
        return Integer.toString(--days) + str.substring(idx);
    }
}

Related

  1. formatRfc3339Date(Date date)
  2. formatRFC822(Date date)
  3. formatRFC822(Date date, Locale locale)
  4. formatRFC822(Date date, String timezone)
  5. formatRfc822Date(Date date)
  6. formatSDate(java.util.Date date)
  7. formatShortDate(java.util.Date date)
  8. formatShortTime()
  9. formatSimpleTimeAndDateString(Date date)