Java Time Format formatToTimeStr(String str)

Here you can find the source of formatToTimeStr(String str)

Description

format str to time str (hh:mm)

License

Open Source License

Parameter

Parameter Description
str String to be converted

Return

String

Declaration

public static String formatToTimeStr(String str) 

Method Source Code

//package com.java2s;
/*//from ww  w  .j a va  2  s. co  m
 * File: $RCSfile$
 *
 * Copyright (c) 2005 Wincor Nixdorf International GmbH,
 * Heinz-Nixdorf-Ring 1, 33106 Paderborn, Germany
 * All Rights Reserved.
 *
 * This software is the confidential and proprietary information
 * of Wincor Nixdorf ("Confidential Information"). You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered
 * into with Wincor Nixdorf.
 */

public class Main {
    /**
     * format str to time str (hh:mm)
     *
     * @param str String to be converted
     * @return String
     */
    public static String formatToTimeStr(String str) {
        String result = "";
        if (str != null && str.length() > 0) {
            try {
                result = str.substring(0, 2) + ":" + str.substring(2);
            } catch (Exception e) {
                e.printStackTrace();
                result = str;
            }
        }
        return result;
    }
}

Related

  1. formatTimeTakenNs(long startTimeNs, String message)
  2. formatTimeToString(long milisec)
  3. formatTimeToString(long seconds)
  4. formatTimeUnits(double nanos)
  5. formatTimeZoneID(String id)
  6. formatUptime(long uptime)
  7. formatVideoRecordingTime(long t)
  8. getCalendarByDateTime(int dateTime, String dateFormat)
  9. getCurDateTime(String formatStr)