我想以HHhMM格式显示时间。例如,如果时间是09:30 AM,我想将其显示为上午9点45分。我尝试以下方法: -如何以java格式显示HHhMM格式的时间?
import java.util.*;
import java.text.*;
public class PS6 {
public static void main(String args[]) {
Date dNow = new Date();
SimpleDateFormat ft =
new SimpleDateFormat ("E yyyy.MM.dd 'at' HHhMM a");
System.out.println("Current Date: " + ft.format(dNow));
}
}
但前作产量
Current Date: Fri 2016.10.21 at 14210 PM
这是不正确。
任何人都可以请在这帮助我。
什么是你想看到正确的字符串? “HHhMM”格式中的小h是什么? –
你尝试使用转义'新的SimpleDateFormat(“'yyyy.MM.dd'在'HH'h'MM a”);'? – DimaSan
可能重复[如何在SimpleDateFormat中插入特殊字符?](http://stackoverflow.com/questions/2912149/how-can-i-insert-special-characters-in-simpledateformat) – DimaSan