import javatextSimpleDateFormat;
import javautilCalendar;
import javautilScanner;
public class Cat {
public static void main(String[] args) {
Systemoutprint("Please input a date in format yyyy-MM-dd HH:mm:ss: ");
String input = new Scanner(Systemin)nextLine()trim();
try {
Calendar cal = CalendargetInstance();
calsetTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")parse(input));
caladd(CalendarHOUR, 100);
String date = new SimpleDateFormat("HH:mm:SS yyyy/MM/dd")format(calgetTime());
Systemoutprintln(date);
} catch (ParseException e) {
Systemoutprintln("日期时间不正确");
}
}
}
------------------测试
Please input a date in format yyyy-MM-dd HH:mm:ss: 2011-6-30 3:10:10
07:10:00 2011/07/04import javautilDate;
import javatextSimpleDateFormat;
class dayTime
{
public static void main(String args[])
{
Date nowTime=new Date();
Systemoutprintln(nowTime);
SimpleDateFormat time=new SimpleDateFormat("yyyy MM dd HH mm ss");
Systemoutprintln(timeformat(nowTime));
}
}import javatextSimpleDateFormat;
import javautilDate;
/
日期格式化问题
@author Administrator
/
public class DateFormatTest {
public static void main(String[] args) {
Date d = new Date();
// "yyyy-MM-dd HH/mm/ss", "yyyy-MM-dd HH时mm分ss秒",
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH时mm分ss秒");
Systemoutprintln(formatterformat(d));
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)