Here you can find the source of timeToString(Time t)
Parameter | Description |
---|---|
t | The time to convert to a String |
public static String timeToString(Time t)
//package com.java2s; /*/*from w w w . java 2s . com*/ * Copyright 2011, United States Geological Survey or * third-party contributors as indicated by the @author tags. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU 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/ >. * */ import java.sql.Time; public class Main { /** We will represent Times as hh/dd and trade them back and forth with *sister routine stringToTime() *@param t The time to convert to a String *@return The String with time in hh:mm am/pm */ public static String timeToString(Time t) { String s = t.toString(); s = s.substring(0, 5); if (s.substring(0, 2).compareTo("12") > 0) { int ih = Integer.parseInt(s.substring(0, 2)) - 12; s = "" + ih + s.substring(2, 5); s = s + " pm"; } else { if (s.substring(0, 2).equals("12")) s = s + " pm"; else s = s + " am"; } return s; } }