Date 获取日期 SimpleDateFormat

package Baozhuang;

import java.text.SimpleDateFormat;
import java.util.Date;

public class DateTest {
    public static void main(String[] args) {
        //获取当前日期和时间
        Date date = new Date();
        System.out.println("当前时间:"+date);

        //对当前日期进行规范    日期类型与字符串转换 SimpleDateFormat
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
        String time = dateFormat.format(date);
        System.out.println("年-月-日  时:分:秒"+time);

        //E月份里的星期几
        SimpleDateFormat dateFormat2 = new SimpleDateFormat("E");
        String week = dateFormat2.format(date);
        System.out.println("今天是:"+week);
        //F月份里的星期 同W
        SimpleDateFormat dateFormat3 = new SimpleDateFormat("F");
        String week2 = dateFormat3.format(date);
        System.out.println("今天是第"+week2+"周");

        //W月份中的周数     w年份中的周数
        SimpleDateFormat dateFormat4 = new SimpleDateFormat("W");
        String week3 = dateFormat4.format(date);
        System.out.println("今天是第:"+week3+"周");
        //a  am/pm标记
        SimpleDateFormat dateFormat5 = new SimpleDateFormat("a");
        String day = dateFormat5.format(date);
        System.out.println("上午/下午"+day);

    }
}

时间: 2024-08-17 02:14:46

Date 获取日期 SimpleDateFormat的相关文章

包装类、Date类、SimpleDateFormat类(基本数据类型<-->String<-->日期/时间)

基本数据类型-->String "+"字符串连接符 基本数据类型<--String 基本数据类型 包装类 String-->xxx xxx parseXxx(String s) byte  Byte byte parseByte(String s) short   Short short parseShort(String s) int  Integer int parseInt(String s) long Long long parseLong(String s)

jquery 获取日期 date 对象、 判断闰年

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>时间</title> <script src="scripts/jquery-1.7.1.min.js"></script> </head> <body> <script type=&

Calendar类,获取日期

import java.util.*;import java.text.*;public class Text9{     public static void main(String args[]){          //创建Calendar对象          Calendar c=Calendar.getInstance();                   //获取时间          Date d=c.getTime();          System.out.printl

java中获取日期和时间的方法总结

1.获取当前时间,和某个时间进行比较.此时主要拿long型的时间值. 方法如下:  要使用 java.util.Date .获取当前时间的代码如下 Date date = new Date(); date.getTime() ; 还有一种方式,使用 System.currentTimeMillis() ;都是得到一个当前的时间的long型的时间的毫秒值,这个值实际上是当前时间值与1970年一月一号零时零分零秒相差的毫秒数 一.获取当前时间,   格式为:   yyyy-mm-dd   hh-mm

Java 中常用的类:包括基本类型的包装类、Date 类、SimpleDateFormat 类、 Calendar 类、 Math 类

JAVA中的包装类 包装类里没有String,它是引用数据类型 基本类型是不能调用方法的,而其包装类具有很多方法 包装类主要提供了两大类方法: 1. 将本类型和其他基本类型进行转换的方法 2. 将字符串和本类型及包装类互相转换的方法 基本类型 对应的包装类 byte Byte short Short int Integer long Long float Float double Double char Character boolean Boolean Integer m=new Intege

java之Date类及SimpleDateFormat类

1 public class Demo6_Date { 2 3 /* 4 * A: 类Date表示特定的瞬间,精确到毫秒 5 * B:构造方法 6 * public Date() 无参时代表当前时间 7 * public Date(long date) 传入参数时代表获取特定时间的 8 * C:成员方法 9 * public long getTime() 获取时间的毫秒值,类似于System.currentTimeMillis() 10 * public void setTime(long ti

在 Java 8 中获取日期

前言 前面一篇文章写了<SimpleDateFormat 如何安全的使用?>, 里面介绍了 SimpleDateFormat 如何处理日期/时间,以及如何保证线程安全,及其介绍了在 Java 8 中的处理时间/日期默认就线程安全的 DateTimeFormatter 类.那么 Java 8 中该怎么样处理生活中常见的一些日期/时间呢?比如:计算一周后的日期:计算一年前或一年后的日期:检查闰年等. 接下来创建了 20 个基于任务的实例来学习 Java 8 的新特性.从最简单创建当天的日期开始,然

关于Java类Calendar做统计时 获取日期的一些常见操作

1.获取本周的周一到周日 //通过调整日历,获得本天所属周的周一和周日 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); Calendar cal=new GregorianCalendar(); cal.setFirstDayOfWeek(Calendar.MONDAY); cal.setTime(new Date()); cal.set(Calendar.DAY_OF_WEEK, cal.getFirstDayOf

Java连载78-深入自动拆装箱、Date类和SimpleDateFormat格式化

一.深入自动拆装箱 1.直接举例: public class D78_AutomaticUnpackingAndPacking{ public static void main(String[] args){ Integer i1 = new Integer(10); Integer i2 = new Integer(10); //这里不会自动进行拆箱 System.out.println(i1==i2);//false //比较两个Integer类型的数据是否相等,不能用“==" //Inte