java将时间戳转为字符串 将字符串转为时间戳
来源:互联网 发布:用手机听公务员网络课 编辑:程序博客网 时间:2024/05/16 01:49
* @Description 获取当前时间
* @author YuSy
* @return
*/
public static String getNowDateTime() {
Date date = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-M-d HH:mm");
return sdf.format(date); //当期日期
}
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
df.format(new Date())
/**
* @Description 是否大于现在的时间
* @author YuSy
* @param time "yyyy-M-d HH:mm"时间格式
* @return
*/
public static boolean isGreaterNowTime(String time){
if (isNull(time)) {
return false;
}
long nowTime=System.currentTimeMillis();
long theTime=Long.valueOf(getTime(time,"yyyy-M-d HH:mm"));
if (theTime>nowTime) {
return true;
}else{
return false;
}
}
public static String getTheTime(String cc_time) {
if (isNull(cc_time)) {
return "";
}
long lcc_time = Long.parseLong(cc_time);
SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy/MM/dd");
return sdf2.format(lcc_time);
}
/**
* 将字符串转为时间戳
* @param user_time 例如:user_time = "2015-1-3 09:03";
* @param format 格式 例如: "yyyy-M-d HH:mm";
* @return
*/
public static String getTime(String user_time,String format) {
SimpleDateFormat sdf = new SimpleDateFormat(format);
Date d;
if (isNull(user_time)) {
return "";
}
try {
d = sdf.parse(user_time);
long l = d.getTime();
return String.valueOf(l);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return "";
}
/**
* java将时间戳转为字符串
*
* @param cc_time 例如:cc_time="1291778220"
* @param format 格式 例如: "yyyy-MM-dd HH:mm:ss";
* @return 返回此形式的数据yyyy-MM-dd HH:mm:ss
*/
public static String getStrTime2(String cc_time,String format) {
long lcc_time = Long.parseLong(cc_time);
return getStrTime2(lcc_time, format);
}
/**
* java将时间戳转为字符串
*
* @param cc_time 例如:cc_time=1291778220
* @param format 格式 例如: "yyyy-MM-dd HH:mm:ss";
* @return 返回此形式的数据yyyy-MM-dd HH:mm:ss
*/
public static String getStrTime2(long cc_time,String format) {
SimpleDateFormat sdf2 = new SimpleDateFormat(format);
return sdf2.format(cc_time);
}
String timeBefore=OtherUtil.getTime(time, "yyyy-MM-dd HH:mm:ss");
String timeAfter=OtherUtil.getStrTime2(timeBefore, "yy-MM-dd HH:mm");
- 将时间戳转为字符串
- Scala 将时间字符串转为时间戳
- java将时间戳转为字符串 将字符串转为时间戳
- js:将时间obj转为json字符串
- 将字符串时间转为毫秒值
- python 时间戳转为字符串
- python 字符串转为时间戳
- ios 将时间戳转为时间类型
- python 时间字符串转为时间戳
- android 将时间戳转为代表"距现在多久之前"的字符串
- android 将时间戳转为代表"距现在多久之前"的字符串
- android 将时间戳转为代表"距现在多久之前"的字符串
- android将时间戳转为代表”距现在多久之前”的字符串
- 将整型转为字符串
- 将文本文件转为字符串
- 将字符串转为数字
- 将字符串转为数字
- 将字符串转为整数
- JAVA-原创差异化加密---觉得还行您就看看,觉得不行也没关系
- 标题:切面条-
- UVA Bicoloring (交叉染色)
- 删除WebLogic 10的缓存
- 重载两同三不同
- java将时间戳转为字符串 将字符串转为时间戳
- threadLocal遇上线程池导致局部变量变化
- sysfs-procfs
- ListView中含有Button时setOnclickListener应写在Adapter的什么地方
- Oracle学习笔记安装篇之在Redhat Enterprise Linux 7.0 x86_64下安装Oracle11g R2
- js和PHP 时间戳与日期转换
- 电脑出现蓝屏的解决方法
- Java程序最基本的加载流程
- Android开发--瀑布流效果的实现