java enum 笔记 日期时间格式化
时间:2010-09-03 来源:吴X
java 的enum也是个类。
public enum Action {
TURN_LEFT,
TURN_RIGHT,
SHOOT;
public String GetDescription(){
switch(this.ordinal()){
case 0: return "left";
case 1: return "right";
case 2: return "shoot";
default:return null;
}
}
}
e.g.2:
代码 public enum ActionAbstract {
TURN_LEFT
{
public String GetDesc(){return "left";}
},
TURN_RIGHT{
public String GetDesc(){return "right";}
},
SHOOT{
public String GetDesc(){return "shoot";}
}; //以;结束
public abstract String GetDesc();
}
ps:
for(Action act : Action.values()){
System.out.printf( "%s %s %n", act.ordinal() , act );
}
//日期时间格式化表达式:
System.out.println(
String.format( "%1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS",new Date() )
);
System.out.printf("%1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS",new Date() );
相关阅读 更多 +