1. java怎样将string时间戳转换为date
1首先把字符串转成标准的时间格式:
String time = "xxxxxxx";
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String plan = sdf.format();
2.再次转成Date
sdf.parse(plan);
2. 如何将android时间戳转换成时间
时间戳就是如1377216000000 这种格式我们在mysql数据库中会经常用到把时间转换成时间戳或把时间戳转换成日期格式了,下面我来介绍安卓中时间戳操作转换方法。
一、原理
时间戳的原理是把时间格式转为十进制格式,这样就方便时间的计算。好~ 直接进入主题。(下面封装了一个类,有需要的同学可以参考或是直接Copy 就可以用了。)
如: 2013年08月23日 转化后是 1377216000000
二、步骤
1、创建 DateUtilsl类。
代码如下 复制代码
importjava.text.ParseException;
importjava.text.SimpleDateFormat;
importjava.util.Date;
/*
* @author Msquirrel
*/
public class DateUtils {
privateSimpleDateFormat sf = null;
/*获取系统时间 格式为:"yyyy/MM/dd "*/
public static String getCurrentDate() {
Date d = newDate();
sf = newSimpleDateFormat("yyyy年MM月dd日");
returnsf.format(d);
}
/*时间戳转换成字符窜*/
public static String getDateToString(long time) {
Date d = newDate(time);
sf = newSimpleDateFormat("yyyy年MM月dd日");
returnsf.format(d);
}
/*将字符串转为时间戳*/
public static long getStringToDate(String time) {
sdf = newSimpleDateFormat("yyyy年MM月dd日");
Date date = newDate();
try{
date = sdf.parse(time);
} catch(ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
returndate.getTime();
}
2、在对应使用的地方调用就可以了。
代码如下 复制代码
DateUtils.getCurrentDate(); //获取系统当前时间
DateUtils.getDateToString(时间戳); //时间戳转为时间格式
DateUtils.getStringToDate("时间格式");//时间格式转为时间戳
3. Java里面怎么获取指定日期的时间戳,比如日期格式是20130304,字符串类型的,怎么获取这个时间的时间戳
SimpleDateFormat df = new SimpleDateFormat("yyyy年MM月dd日");//设置日期格式
String msg =df.format(new Date());
new Date()替换成你需要格式化的日期
4. java怎么把当前时间转换为16进制存储只保存年月日,且只用4个字节,取值的时候可以添加字符串获得时间
* Convert byte[] to hex string.这里我们可以将byte转换成int,然后利用Integer.toHexString(int)
*来转换成16进制字符串。
* @param src byte[] data
* @return hex string
*/
public static String bytesToHexString(byte[] src){
StringBuilder stringBuilder = new StringBuilder("");
if (src == null || src.length <= 0) {
return null;
}
for (int i = 0; i < src.length; i++) {
int v = src[i] & 0xFF;
String hv = Integer.toHexString(v);
if (hv.length() < 2) {
stringBuilder.append(0);
}
stringBuilder.append(hv);
}
return stringBuilder.toString();
}
此方法能将byte[]转化成16进制字符串,希望能帮到你。
5. java怎么判断是否为时间戳
时间戳是指从1970年1月1日到现在的时间.通常为秒或者毫秒.
理论上任何一个int或者long都能解析成为一个时间.
如果一定要检测,则需要给定一个条件,比如从什么时候,到什么时候.可以比对判断.
6. java TimeStamp 转换为 yyyy-MM-dd格式的date类型
实现思路就是先将Timestamp转换为字符串,之后字符串转换为日期类型。举例:Long l = System.currentTimeMillis();//获取当前的Timestamp值
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");//定义日期类型格式
String str2 = Timestamp.valueOf(format.format(l));//转换为字符串
//System.out.println(str2);//打印获取的字符串
Date date = format .parse(str2);//格式化获取到的日期,
System.out.println(date);
输出结果:2015-06-27。
7. java如何将时间戳转换为时间字符串
public static String getStrTime(String cc_time) {
String re_StrTime = null;
SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日HH时mm分ss秒");
// 例如回:答cc_time=1291778220
long lcc_time = Long.valueOf(cc_time);
re_StrTime = sdf.format(new Date(lcc_time * 1000L));
return re_StrTime;
}