DateDemo 时间格式类 SimpleDateFormat DateFormat
2016-02-19 16:06
387 查看
import java.util.Date;
import java.text.DateFormat;
import java.util.Locale;
import java.text.SimpleDateFormat;
import java.text.ParsePosition;
class DateDemo
{
public static void main(String[] args)
{
Date date=new Date();
System.out.println(date);
System.out.println(date.getTime());
DateFormat df=DateFormat.getDateInstance(DateFormat.LONG,new Locale("SIMPLE_CHINESE","CHINA"));
DateFormat df1=DateFormat.getDateTimeInstance(DateFormat.FULL,DateFormat.MEDIUM);
//date.setTime(1455861256820L);
//System.out.println(DateFormat.getDateTimeInstance().format(date));
System.out.println(df1.format(date));
//SimpleDateFormate可以自定义格式,DateFormate只能SHORT MEDIUM LONG FULL几个模式。
SimpleDateFormat sdf=new SimpleDateFormat();
System.out.println(sdf.toPattern());
SimpleDateFormat sdf2=new SimpleDateFormat("'@' G yyyyy-MM-dd HH:mm:ss:S zzz");
System.out.println(sdf2.format(date));
Date date2=sdf2.parse("@ 公元 02016-02-19 15:21:09:801 CST",new ParsePosition(0)); //如果给定一个字符串,从这个里面抽取一个date对象,就得先做一个匹配这个字符串的SDF对象;用这个对象就可以匹配的抽出这个date对象了。
System.out.println(date2);
}
}
import java.text.DateFormat;
import java.util.Locale;
import java.text.SimpleDateFormat;
import java.text.ParsePosition;
class DateDemo
{
public static void main(String[] args)
{
Date date=new Date();
System.out.println(date);
System.out.println(date.getTime());
DateFormat df=DateFormat.getDateInstance(DateFormat.LONG,new Locale("SIMPLE_CHINESE","CHINA"));
DateFormat df1=DateFormat.getDateTimeInstance(DateFormat.FULL,DateFormat.MEDIUM);
//date.setTime(1455861256820L);
//System.out.println(DateFormat.getDateTimeInstance().format(date));
System.out.println(df1.format(date));
//SimpleDateFormate可以自定义格式,DateFormate只能SHORT MEDIUM LONG FULL几个模式。
SimpleDateFormat sdf=new SimpleDateFormat();
System.out.println(sdf.toPattern());
SimpleDateFormat sdf2=new SimpleDateFormat("'@' G yyyyy-MM-dd HH:mm:ss:S zzz");
System.out.println(sdf2.format(date));
Date date2=sdf2.parse("@ 公元 02016-02-19 15:21:09:801 CST",new ParsePosition(0)); //如果给定一个字符串,从这个里面抽取一个date对象,就得先做一个匹配这个字符串的SDF对象;用这个对象就可以匹配的抽出这个date对象了。
System.out.println(date2);
}
}
相关文章推荐
- 手势冲突解决方案
- ssh 密钥模式免输密码
- jquery基础
- win7 启动后内存占用达到99% 解决方案
- poj seek the name,seek the fame
- redis和memcache
- 前端自动化测试探索
- response.setContentType()的作用及参数
- Dell T110 S100如何创建磁盘阵列
- css基础
- 【Linux运维入门】MongoDb启动报错:ERROR: child process failed, exited with error number xx
- Android Studio导入外部library
- Unity3D面试题整合
- Android APK签名介绍01
- Qt用QAxObject读取excel编译出错问题解决
- Activity生命周期
- Ubuntu下找不到php5,phpize等可执行程序的解决办法
- Application Loader上传app程序
- html基础
- IOS抽出接口对象中集合数据存入一个单一集合