文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>SimpleDateFormat is a concrete class for formattin

SimpleDateFormat is a concrete class for formattin

时间:2010-06-08  来源:meteorm

SimpleDateFormat is a concrete class for formatting and parsing dates in a locale-sensitive manner. It allows for formatting (date -> text), parsing (text -> date), and normalization. SimpleDateFormat allows you to start by choosing any user-defined patterns for date-time formatting. However, you are encouraged to create a date-time formatter with either getTimeInstance, getDateInstance, or getDateTimeInstance in DateFormat. Each of these class methods can return a date/time formatter initialized with a default format pattern. You may modify the format pattern using the applyPattern methods as desired. For more information on using these methods, see DateFormat. package c1; import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class Test1 { 
 

  public static void main(String[] args) {
 
     SimpleDateFormat sdf = new SimpleDateFormat ("MM/dd/yyyy HH:mm:ss");
     SimpleDateFormat sdf1 = new SimpleDateFormat ("yyyy-MM-dd HH:mm:ss");
     //日期转换成字符串
     String str=sdf.format(new Date());
     System.out.println(str);
    
     //   字符串转换成日期
     try {
   Date d1=sdf.parse(str);
   String str1=sdf1.format(d1);
   System.out.println(str1);
  } catch (ParseException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
  }
}
Output:
06/08/2010 15:08:22
2010-06-08 15:08:22
相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载