转换成Date形式
来源:互联网 发布:java怎么写代码 编辑:程序博客网 时间:2024/05/19 14:52
package yaSoft.Util;
import java.sql.Time;
import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
public class TimeUtil {
/**
* 转换成Date形式
* @param Time
* @return
*/
public static Date getTime(String Time){
SimpleDateFormat sdf =new SimpleDateFormat("yyyy-MM-dd");
Date date = new Date();
try {
date = sdf.parse(Time);
} catch (Exception e) {
e.printStackTrace();
}
return date;
}
/**
* 转换成datetime形式
* @param operatingTime
* @return
*/
public static Timestamp getOperateTime(String operatingTime){
Timestamp ts = new Timestamp(System.currentTimeMillis());
try {
ts = Timestamp.valueOf(operatingTime);
System.out.println(ts);
} catch (Exception e) {
e.printStackTrace();
}
return ts;
}
//datetime转换成string形式
public static String getDateTime(Timestamp operatingTime){
SimpleDateFormat sdf =new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String time = "";
try {
//方法一
time = sdf.format(operatingTime);
System.out.println(time);
/* //方法二
time = ts.toString();
System.out.println(time); */
} catch (Exception e) {
e.printStackTrace();
}
return time;
}
/**
* datetime转换成string形式 格式为yyyy-MM-dd
* @param operatingTime
* @return
*/
public static String getDate(Timestamp operatingTime){
SimpleDateFormat sdf =new SimpleDateFormat("yyyy-MM-dd");
String time = "";
try {
//方法一
time = sdf.format(operatingTime);
System.out.println(time);
/* //方法二
time = ts.toString();
System.out.println(time); */
} catch (Exception e) {
e.printStackTrace();
}
return time;
}
/**
* 获取系统时间转换成datetime类型
* @return
*/
public static Timestamp getSysTime(){
Date date=new Date();
SimpleDateFormat dateFormat =new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String currTime=dateFormat.format(date);
Timestamp ts = new Timestamp(System.currentTimeMillis());
try {
ts = Timestamp.valueOf(currTime);
System.out.println(ts);
} catch (Exception e) {
e.printStackTrace();
}
return ts;
}
/**
* 获取系统时间转换成datetime类型
* @return
*/
public static Time getSysTimes(){
Date date=new Date();
SimpleDateFormat dateFormat =new SimpleDateFormat("HH:mm:ss");
String currTime=dateFormat.format(date);
Time ts = new Time(System.currentTimeMillis());
try {
ts = Time.valueOf(currTime);
System.out.println(ts);
} catch (Exception e) {
e.printStackTrace();
}
return ts;
}
/**
* 获取系统时间转换成date类型
* @return
*/
public static Date getSysDate(){
Date date=new Date();
SimpleDateFormat sdf =new SimpleDateFormat("yyyy-MM-dd");
String currTime=sdf.format(date);
try {
date = sdf.parse(currTime);
} catch (Exception e) {
e.printStackTrace();
}
return date;
}
public static String getTime(){
Date date=new Date();
SimpleDateFormat dateFormat =new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
String currTime=dateFormat.format(date);
return currTime;
}
public static String getYear(){
Date date=new Date();
SimpleDateFormat dateFormat =new SimpleDateFormat("yyyy");
String currTime=dateFormat.format(date);
return currTime;
}
public static String getOrderTime(){
Date date=new Date();
SimpleDateFormat dateFormat =new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String currTime=dateFormat.format(date);
return currTime;
}
public static String getPayTime(){
Date date=new Date();
SimpleDateFormat dateFormat =new SimpleDateFormat("yyyyMMddhhmmss");
String currTime=dateFormat.format(date);
return currTime;
}
public static String getPayTime2(){
Date date=new Date();
SimpleDateFormat dateFormat =new SimpleDateFormat("yyyy/MM/dd");
String currTime=dateFormat.format(date);
return currTime;
}
public static String getTimes(Date time){
SimpleDateFormat dateFormat =new SimpleDateFormat("yyyy-MM-dd");
String currTime=dateFormat.format(time);
return currTime;
}
public static String getDateTimes(Date time){
SimpleDateFormat dateFormat =new SimpleDateFormat("yyyy-MM-dd");
String currTime=dateFormat.format(time);
return currTime;
}
public static String getDateTimes2(Date time){
SimpleDateFormat dateFormat =new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String currTime=dateFormat.format(time);
return currTime;
}
public static void main(String[] args) {
String i ="2,3,";
System.out.println(i.substring(i.length()-1,i.length()).equals(","));
System.out.println();
}
public static String getImagesTime(){
Date date=new Date();
SimpleDateFormat dateFormat =new SimpleDateFormat("yyyyMMddHHmmss");
String currTime=dateFormat.format(date);
return currTime;
}
public static String getWeixinTime(){
Date date=new Date();
SimpleDateFormat dateFormat =new SimpleDateFormat("MM月dd日");
String currTime=dateFormat.format(date);
return currTime;
}
public static String getDay(){
Date date=new Date();
SimpleDateFormat dateFormat =new SimpleDateFormat("dd");
String currTime=dateFormat.format(date);
return currTime;
}
/**
*格林时间转换成字符串
*@author lmc
*@time 2014-12-11 17:29:11
*/
public static String greenwichMeanTime(String timeStr){
Date d = null;
SimpleDateFormat sdfSource = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US);
SimpleDateFormat sdfTarget = new SimpleDateFormat("yyyy-MM-dd", Locale.US);//设置显示格式
try {
d = sdfSource.parse(timeStr);
} catch (ParseException e) {
return null;
}
return sdfTarget.format(d);
}
/**
* 格林时间转转换成date类型
* @return
*/
public static Date greenwichMeanTimes(String timeStr){
Date date=new Date();
SimpleDateFormat sdf =new SimpleDateFormat("yyyy-MM-dd");
try {
date = sdf.parse(timeStr);
} catch (Exception e) {
e.printStackTrace();
}
return date;
}
/**
* 把毫秒转化成日期
* @param dateFormat(日期格式,例如:MM/ dd/yyyy HH:mm:ss)
* @param millSec(毫秒数)
* @return
*/
@SuppressWarnings("unused")
public static String transferLongToDate(String dateFormat,Long millSec){
SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);
Date date= new Date(millSec);
return sdf.format(date);
}
}
import java.sql.Time;
import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
public class TimeUtil {
/**
* 转换成Date形式
* @param Time
* @return
*/
public static Date getTime(String Time){
SimpleDateFormat sdf =new SimpleDateFormat("yyyy-MM-dd");
Date date = new Date();
try {
date = sdf.parse(Time);
} catch (Exception e) {
e.printStackTrace();
}
return date;
}
/**
* 转换成datetime形式
* @param operatingTime
* @return
*/
public static Timestamp getOperateTime(String operatingTime){
Timestamp ts = new Timestamp(System.currentTimeMillis());
try {
ts = Timestamp.valueOf(operatingTime);
System.out.println(ts);
} catch (Exception e) {
e.printStackTrace();
}
return ts;
}
//datetime转换成string形式
public static String getDateTime(Timestamp operatingTime){
SimpleDateFormat sdf =new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String time = "";
try {
//方法一
time = sdf.format(operatingTime);
System.out.println(time);
/* //方法二
time = ts.toString();
System.out.println(time); */
} catch (Exception e) {
e.printStackTrace();
}
return time;
}
/**
* datetime转换成string形式 格式为yyyy-MM-dd
* @param operatingTime
* @return
*/
public static String getDate(Timestamp operatingTime){
SimpleDateFormat sdf =new SimpleDateFormat("yyyy-MM-dd");
String time = "";
try {
//方法一
time = sdf.format(operatingTime);
System.out.println(time);
/* //方法二
time = ts.toString();
System.out.println(time); */
} catch (Exception e) {
e.printStackTrace();
}
return time;
}
/**
* 获取系统时间转换成datetime类型
* @return
*/
public static Timestamp getSysTime(){
Date date=new Date();
SimpleDateFormat dateFormat =new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String currTime=dateFormat.format(date);
Timestamp ts = new Timestamp(System.currentTimeMillis());
try {
ts = Timestamp.valueOf(currTime);
System.out.println(ts);
} catch (Exception e) {
e.printStackTrace();
}
return ts;
}
/**
* 获取系统时间转换成datetime类型
* @return
*/
public static Time getSysTimes(){
Date date=new Date();
SimpleDateFormat dateFormat =new SimpleDateFormat("HH:mm:ss");
String currTime=dateFormat.format(date);
Time ts = new Time(System.currentTimeMillis());
try {
ts = Time.valueOf(currTime);
System.out.println(ts);
} catch (Exception e) {
e.printStackTrace();
}
return ts;
}
/**
* 获取系统时间转换成date类型
* @return
*/
public static Date getSysDate(){
Date date=new Date();
SimpleDateFormat sdf =new SimpleDateFormat("yyyy-MM-dd");
String currTime=sdf.format(date);
try {
date = sdf.parse(currTime);
} catch (Exception e) {
e.printStackTrace();
}
return date;
}
public static String getTime(){
Date date=new Date();
SimpleDateFormat dateFormat =new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
String currTime=dateFormat.format(date);
return currTime;
}
public static String getYear(){
Date date=new Date();
SimpleDateFormat dateFormat =new SimpleDateFormat("yyyy");
String currTime=dateFormat.format(date);
return currTime;
}
public static String getOrderTime(){
Date date=new Date();
SimpleDateFormat dateFormat =new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String currTime=dateFormat.format(date);
return currTime;
}
public static String getPayTime(){
Date date=new Date();
SimpleDateFormat dateFormat =new SimpleDateFormat("yyyyMMddhhmmss");
String currTime=dateFormat.format(date);
return currTime;
}
public static String getPayTime2(){
Date date=new Date();
SimpleDateFormat dateFormat =new SimpleDateFormat("yyyy/MM/dd");
String currTime=dateFormat.format(date);
return currTime;
}
public static String getTimes(Date time){
SimpleDateFormat dateFormat =new SimpleDateFormat("yyyy-MM-dd");
String currTime=dateFormat.format(time);
return currTime;
}
public static String getDateTimes(Date time){
SimpleDateFormat dateFormat =new SimpleDateFormat("yyyy-MM-dd");
String currTime=dateFormat.format(time);
return currTime;
}
public static String getDateTimes2(Date time){
SimpleDateFormat dateFormat =new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String currTime=dateFormat.format(time);
return currTime;
}
public static void main(String[] args) {
String i ="2,3,";
System.out.println(i.substring(i.length()-1,i.length()).equals(","));
System.out.println();
}
public static String getImagesTime(){
Date date=new Date();
SimpleDateFormat dateFormat =new SimpleDateFormat("yyyyMMddHHmmss");
String currTime=dateFormat.format(date);
return currTime;
}
public static String getWeixinTime(){
Date date=new Date();
SimpleDateFormat dateFormat =new SimpleDateFormat("MM月dd日");
String currTime=dateFormat.format(date);
return currTime;
}
public static String getDay(){
Date date=new Date();
SimpleDateFormat dateFormat =new SimpleDateFormat("dd");
String currTime=dateFormat.format(date);
return currTime;
}
/**
*格林时间转换成字符串
*@author lmc
*@time 2014-12-11 17:29:11
*/
public static String greenwichMeanTime(String timeStr){
Date d = null;
SimpleDateFormat sdfSource = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US);
SimpleDateFormat sdfTarget = new SimpleDateFormat("yyyy-MM-dd", Locale.US);//设置显示格式
try {
d = sdfSource.parse(timeStr);
} catch (ParseException e) {
return null;
}
return sdfTarget.format(d);
}
/**
* 格林时间转转换成date类型
* @return
*/
public static Date greenwichMeanTimes(String timeStr){
Date date=new Date();
SimpleDateFormat sdf =new SimpleDateFormat("yyyy-MM-dd");
try {
date = sdf.parse(timeStr);
} catch (Exception e) {
e.printStackTrace();
}
return date;
}
/**
* 把毫秒转化成日期
* @param dateFormat(日期格式,例如:MM/ dd/yyyy HH:mm:ss)
* @param millSec(毫秒数)
* @return
*/
@SuppressWarnings("unused")
public static String transferLongToDate(String dateFormat,Long millSec){
SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);
Date date= new Date(millSec);
return sdf.format(date);
}
}
阅读全文
0 0
- 转换成Date形式
- Date 形式转换
- 将西方形式的日期字符串转换成java.util.Date对象
- date.getTime() 转换成 date
- date将秒数转换成日期的字符串表达形式
- Date转换成String
- 金额转换,阿拉伯数字转换成中国传统形式。
- 金额转换,阿拉伯数字转换成中国传统形式。
- 金额转换,阿拉伯数字转换成中国传统形式
- 金额转换,阿拉伯数字转换成中国传统形式。
- simpledateformat String转换成 date;date转换成String
- String转换成date类型
- 将Timestamp转换成Date
- date日期转换成整数
- java String转换成Date
- ISO8601转换成Date类型
- Date格式转换成字符串
- String类型转换成date
- docker的安装
- des对称加密和解密
- flume-kafka整合--实时日志采集
- 使用Knockout实现全选时遇到的问题
- String,StringBuilder和StringBuffer在保存数据方面的区别和原因
- 转换成Date形式
- android触摸事件分发与处理简述
- EasyUI日期格式化
- centos部署postgresql
- Win7删除GRUB For DOS启动项
- 第12周项目4- 拓扑排序算法验证
- 数据结构第十一周项目一_
- java——JVM原理
- CSS3实现动态翻牌效果 仿百度贴吧3D翻牌一次动画特效