格式转化
SimpleDateFormat
package day1211.common;

import java.sql.Date;
import java.sql.Timestamp;
import java.text.SimpleDateFormat; public class DateFormat {
public Date format(String date) throws Exception{
Date time=null;
SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd");
time=new Date(format.parse(date).getTime());
return time;
}
}
import java.text.ParseException;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.*; public class Date { public static void main(String[] args) { /*Set<Integer> a=new TreeSet<>();
a.add(1);
a.add(2);
a.add(3);
a.add(6);
a.add(2);
a.add(5);
Set<Integer> b=new LinkedHashSet<>();
b.add(5);
b.add(3);
b.add(2);
b.add(3);
b.add(1);
b.add(12);
b.add(24);
b.add(13);
for(Integer i:a){
System.out.println(i); }
System.out.println();
for(Integer i:b){ System.out.println(i);
}*/
/*Map<Integer,Integer> a=new HashMap<>();
a.put(1,1);
a.put(2,1);
a.put(5,3);
a.put(4,5);
a.put(3,2);
a.put(2,1);
a.put(9,1);
a.put(6,1);
a.put(24,1);
a.put(12,1);
a.put(14,1);
a.put(13,1);
Map<Integer,Integer> b=new LinkedHashMap<>();
b.put(1,1);
b.put(2,1);
b.put(5,1);
b.put(4,1);
b.put(3,1);
b.put(2,1); System.out.println(a); System.out.println();
System.out.println(b);*/
//Calendar最常用找一年中的哪一天,其他不用
//SimpleDateFormat
//java.sql.TimeStamp yyyy-mm-dd HH:mm:dd带年月日时分秒
//java.sql.Date 不带时分秒
Calendar calendar=Calendar.getInstance();//例如单例模式,为抽象类,只能通过类方法返回类对象
calendar.set(2017,3,21);//重新设置时间否则为电脑时间
//calendar.set(Integer.parseInt("2015"),Integer.parseInt("5"),Integer.parseInt("23"));
System.out.println(calendar.get(calendar.YEAR)+" "+calendar.get(calendar.MONTH)+" "+calendar.get(calendar.DATE));//从0开始为第一月
System.out.println(calendar.get(calendar.DAY_OF_YEAR));//最常用 java.util.Date date=calendar.getTime();
System.out.println(date);
System.out.println(new java.sql.Date(date.getTime()));//转换为数据库上的时间
java.util.Date date1=new java.util.Date("2018/12/31 12:12:12");
System.out.println(date1);
SimpleDateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String info=dateFormat.format(date);
System.out.println(info);
try {
java.util.Date s=dateFormat.parse("2018-03-02 12:12:12");
System.out.println(new java.sql.Date(s.getTime()));
System.out.println(new java.sql.Timestamp(s.getTime()));
} catch (ParseException e){
System.out.println("大");
}
}
//JAVA ORCALE mysql
//yyyy-mm-dd HH:mm:ss yyyy-mm-dd 24hh:mi:si yyyy/MM/dd HH:mm:ss
}

												

java中时间的更多相关文章

  1. java中时间的获取(二)

    java中时间的获取2 /** * 获取数据库操作记录时间 */ public static String getOpreateDbTime() { Calendar c = Calendar.get ...

  2. 【java】JDK1.8时间日期库 新特性 所有java中时间Date的使用

    除了lambda表达式,stream以及几个小的改进之外,Java 8还引入了一套全新的时间日期API,在本篇教程中我们将通过几个简单的任务示例来学习如何使用java 8的这套API.Java对日期, ...

  3. Java中时间格式处理,指定N天/小时等之后的时间

    1)根据当前时间,获取具体的时刻的时间 N天前 M小时之前 可用 new Date().getTime() - 24 * 60 * 60 * 1000*N[N天之前]的方法来获取处理时间之后的具体的值 ...

  4. Java中时间API使用详解

    目录 Java中时间API使用详解 1. 时区概念 2. 几种常见的时间 3. 时间戳 4. Java中的时间API 5. Java8中新添加的时间API 6. 在东八区的机器上获得美国时间 Java ...

  5. JAVA中时间格式转换

    1.将任意日期格式的字符串转换为指定格式的字符串 //默认格式 String s1 = "20190110133236"; //给定格式 String s2 = "201 ...

  6. Java中时间日期格式化

    1.与日期时间相关的类:      第一:java.util.Date;                           将时间作为一个整体使用.处理时,使用Date类较为简便      第二:j ...

  7. Java 中时间处理 System.currentTimeMillis()

    import org.testng.annotations.Test;import java.text.ParseException;import java.text.SimpleDateFormat ...

  8. Java中时间处理

    旧 API:位于 java.util 包中,里面主要有 Date.Calendar.TimeZone 类 新 API:位于 java.time 包中,里面主要有 LocalDateTime.Zoned ...

  9. Java中时间类中的Data类与Time类

    小简博客 - 小简的技术栈,专注Java及其他计算机技术.互联网技术教程 (ideaopen.cn) Data类 Data类中常用方法 boolean after(Date date) 若当调用此方法 ...

  10. java中时间类型的问题

    时间类型:System.currentTimeMillis() 获得的是自1970-1-01 00:00:00.000 到当前时刻的时间距离,类型为longimport java.sql.Date d ...

随机推荐

  1. ASI和TS流有什么区别

    TS流是信源码流,最高码率为44.209 Mbit/s,它是经过信源编码后的压缩码流,为了使欲传输的信源信息在传输速率一定的条件下更快更多地传输,还要把数据进行压缩,也就是通过信源编码去掉信息中多余的 ...

  2. Java之POI的excel导入导出

    一.Apache POI是一种流行的API,它允许程序员使用Java程序创建,修改和显示MS Office文件.这由Apache软件基金会开发使用Java分布式设计或修改Microsoft Offic ...

  3. gSOAP:C++编写服务器端

    1.编写头文件cal.h: //gsoap ns service name: calc //gsoap ns service style: rpc //gsoap ns service encodin ...

  4. Android TextView(EditView)文字底部或者中间 加横线

    Android TextView(EditView)文字底部或者中间 加横线 tv = (TextView) this .findViewById(R.id. text_view ); 中间加横线 t ...

  5. Mysql 授权远程访问

    1.表示从任何主机连接到mysql服务器 GRANT ALL PRIVILEGES ON *.* TO 'user'@'%' IDENTIFIED BY 'password' WITH GRANT O ...

  6. 【POJ】2096 Collecting Bugs(数学期望)

    题目 传送门:QWQ 分析 数学期望 用$ dp[i][j] $表示发现了在$ j $个子系统里面发现了$ i $个bug到$ s $个子系统里面发现了$ n $个bug需要的期望天数. $ dp[0 ...

  7. CentOS6系统优化

    [root@xuliangwei ~]# cat /etc/redhat-release //系统环境CentOS6.6 CentOS release 6.6 (Final) [root@xulian ...

  8. python新里程

    为什么要学Python: 2018年6月开始自学Python.因为自己目前做Linux运维,感觉自己还需要掌握一门开发语言,在Java.python.php之间毫不犹豫的选择了Python,因为Pyt ...

  9. controller 允许跨域访问

    1.在controller 上加上 @CrossOrigin(origins = {"http://localhost:7777", "http://someserver ...

  10. ubuntu上安装 MySQL 启动/停止 连接MySQL

    1.Ubuntu上安装MySQL服务   1.安装服务端   sudo apt-get install mysql-server    2.安装客户端   sudo apt-get install m ...