SimpleDateFormat的使用
来源:互联网 发布:jersey 返回对象json 编辑:程序博客网 时间:2024/05/29 14:34
SimpleDateFormat函数的继承关系:
java.lang.Object
|
+----java.text.Format
|
+----java.text.DateFormat
|
+----java.text.SimpleDateFormat
/**
SimpleDateFormat函数语法:
G 年代标志符
y 年
M 月
d 日
h 时 在上午或下午 (1~12)
H 时 在一天中 (0~23)
m 分
s 秒
S 毫秒
E 星期
D 一年中的第几天
F 一月中第几个星期几
w 一年中第几个星期
W 一月中第几个星期
a 上午 / 下午 标记符
k 时 在一天中 (1~24)
K 时 在上午或下午 (0~11)
z 时区
*/
以下是一些用到的例子:
//拍照的时候 对生成的照片进行命名
public static String getSaveImageFullName() {
return "IMG_" + new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()) + ".jpg";// 照片命名
}
//获取北京时间
public static String stringToDateYear(String dateString){
String time = dateString.substring(6,dateString.length()-2);
Date date = new Date(Long.parseLong(time));
SimpleDateFormat format = new SimpleDateFormat("yyyy.MM.dd HH:mm",new Locale("CHINA"));
format.setTimeZone(TimeZone.getTimeZone("GMT"));
return format.format(date);
}
public static String stringToDate(String dateString){
String time = dateString.substring(6,dateString.length()-2);
Date date = new Date(Long.parseLong(time));
SimpleDateFormat format = new SimpleDateFormat("MM月dd日 HH:mm",new Locale("CHINA"));
format.setTimeZone(TimeZone.getTimeZone("GMT"));
return format.format(date);
}
/**
* 调用此方法输入所要转换的时间戳输入例如(1402733340)输出("2014-06-14 16:09:00")
*
* @param time
* @return
*/
public static String timedate(String time) {
SimpleDateFormat sdr = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
@SuppressWarnings("unused")
long lcc = Long.valueOf(time);
int i = Integer.parseInt(time);
String times = sdr.format(new Date(i * 1000L));
return times;
}/** * 调用此方法输入所要转换的时间戳输入例如(1402733340)输出("2014年06月14日16:09") * * @param time * @return */public static String timet(String time) { SimpleDateFormat sdr = new SimpleDateFormat("yyyy年MM月dd日 HH:mm"); @SuppressWarnings("unused") long lcc = Long.valueOf(time); int i = Integer.parseInt(time); String times = sdr.format(new Date(i * 1000L)); return times;}
- SimpleDateFormat 的使用
- SimpleDateFormat的使用详解
- SimpleDateFormat的方法使用
- SimpleDateFormat 的简单使用
- SimpleDateFormat的使用问题
- SimpleDateFormat的使用
- SimpleDateFormat的简单使用
- SimpleDateFormat 的使用
- SimpleDateFormat类的使用
- Android SimpleDateFormat的使用
- SimpleDateFormat的使用
- SimpleDateFormat类的使用
- SimpleDateFormat的使用
- SimpleDateFormat的使用
- SimpleDateFormat函数使用的例子
- SimpleDateFormat函数使用的例子
- SimpleDateFormat函数使用的例子
- SimpleDateFormat函数使用的例子
- Python实现的检测web服务器健康状况的小程序
- WebViewJavascriptBridge是一个Objective-C与JavaScript进行消息互通的三方库
- 【TensorFlow】数据处理(对图像的处理)
- 链式调用-普通调用
- React Native 学习资源精选仓库(汇聚知识,分享精华)
- SimpleDateFormat的使用
- HbaseTemplate配置进阶:利用Spring自动装配加载HbaseTemplate
- android六大布局和UI组件
- codeforces 122A Lucky Division
- java 金额数字转中文
- 设计模式之生成者与消费者模式
- 设计模式C++实现(16)——状态模式
- ShareSDK新浪微博登录提示 21338:sso package or sign error"
- SVN:Please execute the 'Cleanup' command.