当前位置: 技术问答>java相关
java中怎么能得到2001-8-20 10:10:10的日期格式?
来源: 互联网 发布时间:2015-01-25
本文导语: | /* * @(#) myDateFormat.java 2001-08-20 */ import java.text.*; import java.util.*; public class myDateFormat() { public static void main(String args[]) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); Date...
|
/*
* @(#) myDateFormat.java 2001-08-20
*/
import java.text.*;
import java.util.*;
public class myDateFormat() {
public static void main(String args[]) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
Date myDate = new Date();
System.out.println(sdf.format(myDate));
}
}
希望你满意,你再看看SimpleDateFormat类的帮助,相信你会发现一切都很简单!
* @(#) myDateFormat.java 2001-08-20
*/
import java.text.*;
import java.util.*;
public class myDateFormat() {
public static void main(String args[]) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
Date myDate = new Date();
System.out.println(sdf.format(myDate));
}
}
希望你满意,你再看看SimpleDateFormat类的帮助,相信你会发现一切都很简单!
|
Date d=new Date ();
gTime=String.valueOf (d.getYear()+1900)+"-"+String.valueOf (d.getMonth()+1)+"-"+String.valueOf (d.getDate())+ " " +String.valueOf (d.getHours ())+":"+String.valueOf (d.getMinutes ())+":"+String.valueOf (d.getSeconds());
gTime=String.valueOf (d.getYear()+1900)+"-"+String.valueOf (d.getMonth()+1)+"-"+String.valueOf (d.getDate())+ " " +String.valueOf (d.getHours ())+":"+String.valueOf (d.getMinutes ())+":"+String.valueOf (d.getSeconds());
|
public String reformat()
{
Date today = new Date();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy.MM.dd G 'at' hh:mm:ss z");
try
{
String dateString = formatter.format(today);
return dateString;
} catch (IllegalArgumentException iae) {
result.setForeground(Color.red);
result.setText("Error: " + iae.getMessage());
}
}
{
Date today = new Date();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy.MM.dd G 'at' hh:mm:ss z");
try
{
String dateString = formatter.format(today);
return dateString;
} catch (IllegalArgumentException iae) {
result.setForeground(Color.red);
result.setText("Error: " + iae.getMessage());
}
}