I have java.sql.Timestamp and I would like to deduct the date and show it in 12 hours of fashion, e.g. (18:42 as 6: 42pm)
I tried:
public static string formatTimstamp a.st.whalhauhaur (java.sql.Timestamp stamp) {string stamp string = Stamp.toString (); String hms = stampString.split ("") [1]; String [] hmsArray = hms.split (":"); Int hours = integer Parasent (HMSERE [0]); Int Minutes = Integer .Portset (HMSERE [1]); Int seconds = integer ParisInt (HMSERE [2]); // just wants the string suffix = "" in seconds; If (hours> 12) {hours = hour -12; Suffix = "PM"; } And if (hours == 12) {prefix = "prime minister"; } And {suffix = "AM"; } String low = ""; If (minutes & lt; 10) {lessThanTen = "0"; } Return String.format ("% i:% s% i% s", hours, less money, minutes, suffix); } I get (Exception in thread "Thread-14" java.lang.NumberFormatException: for input string: "06.0"), but I never give it a decimal.
does what you want.
date format = new simpledate format ("h: mm a"); String str = format.format (timestamp); Edit: The version posted to someone else with "K" in the format will return hours between 0-11. It will return 1-12, which can be for you.
Comments
Post a Comment