一、获得当前时间
1、
SimpleDateFormat tempDate = new SimpleDateFormat("yyyy-MM-dd" + " " + "HH:mm:ss");
String datetime = tempDate.format(new java.util.Date());
2、
int yyyy, mm, dd;
Calendar c = Calendar.getInstance();
yyyy = c.get(Calendar.YEAR);
mm = c.get(Calendar.MONTH) + 1;
dd = c.get(Calendar.DAY_OF_MONTH);
二、JSF获得系统路径
public static String getConfPath() {
FacesContext context = FacesContext.getCurrentInstance();
ServletContext servletContext =
(ServletContext)context.getExternalContext().getContext();
String path = servletContext.getRealPath("/WEB-INF");
return path;
}
FacesContext context = FacesContext.getCurrentInstance();
ServletContext servletContext =
(ServletContext)context.getExternalContext().getContext();
String path = servletContext.getRealPath("/WEB-INF");
return path;
}
三、
Java
里数字转字符串前面自动补0的实现
- /**
- * Java 里数字转字符串前面自动补0的实现。
- *
- */
- public class TestStringFormat {
- public static void main(String[] args) {
- int youNumber = 1 ;
- // 0 代表前面补充0
- // 4 代表长度为4
- // d 代表参数为正数型
- String str = String.format( "%04d" , youNumber);
- System.out.println(str); // 0001
- }
- }