欢迎光临
我们一直在努力

java设置时间格式,JAVA中如何控制日期格式

本文目录一览

  • 1,JAVA中如何控制日期格式
  • 2,java中自定义时间类型为yyyyMMdd
  • 3,java中如何对日期进行格式处理
  • 4,java中如何设置时间和显示时间
  • 5,java 时间格式的转换

1,JAVA中如何控制日期格式

调用日期函数
和普通的1样的设置
在日程管理里面修改
论坛里看看吧
这个没设置过,论坛里看看吧
卡萨就单10多年

JAVA中如何控制日期格式

2,java中自定义时间类型为yyyyMMdd

楼主的意思是要在页面上显示为yyyy-MM-dd?
截取字符串会吧?然后进行判断返回true或false就行了
new SimpleDataFormat(“yyyy-MM-dd”).format(new Date());
=text(today(),”yyyy-mm-dd”)

java中自定义时间类型为yyyyMMdd

3,java中如何对日期进行格式处理

import java.text.SimpleDateFormat;import java.util.Date;public class test public static void main(String []aa) SimpleDateFormat dateformat1=new SimpleDateFormat(“yyyy-MM-dd HH:mm:ss E”); String a1=dateformat1.format(new Date()); System.out.println(“时间2:”+a1); System.out.println(new Date().getYear()+1900); SimpleDateFormat dateformat2=new SimpleDateFormat(“yyyy年MM月dd日 HH时mm分ss秒 E “); String a2=dateformat2.format(new Date()); System.out.println(“时间2:”+a2); }}执行结果:时间2:2012-5-12 14:27:59 星期六2006时间2:2012年5月12日 13时27分59秒 星期六 就是SimpleDateFormate这个对象再调用它的formate()方法

java中如何对日期进行格式处理

4,java中如何设置时间和显示时间

System.currentmils()获取从格林威治时间到当前的毫秒数。然后你去书上查下吧 具体的我不记得了。
JAVA中获取当前系统时间2011-07-06 20:45 并格式化输出:import java.util.Date;import java.text.SimpleDateFormat;public class NowString public static void main(String[] args) SimpleDateFormat df = new SimpleDateFormat(“yyyy-MM-dd HH:mm:ss”);//设置日期格式 System.out.println(df.format(new Date()));// new Date()为获取当前系统时间 }}设置时间,推荐 使用java.util.Calendar类来进行操作,import java.util.Date;import java.util.Calendar;import java.text.SimpleDateFormat;public class TestDatepublic static void main(String[] args)Date now = new Date();SimpleDateFormat dateFormat = new SimpleDateFormat(“yyyy/MM/dd HH:mm:ss”);//可以方便地修改日期格式String hehe = dateFormat.format( now );System.out.println(hehe);Calendar c = Calendar.getInstance();//可以对每个时间域单独修改int year = c.get(Calendar.YEAR);int month = c.get(Calendar.MONTH);int date = c.get(Calendar.DATE);int hour = c.get(Calendar.HOUR_OF_DAY);int minute = c.get(Calendar.MINUTE);int second = c.get(Calendar.SECOND);System.out.println(year + “/” + month + “/” + date + ” ” +hour + “:” +minute + “:” + second);}}
用qq直接开启视频就好了啊。。

5,java 时间格式的转换

public class myMain public static void main(String[] args) // 日历类 Calendar calendar = Calendar.getInstance();// 实例化 int year = calendar.get(Calendar.YEAR);// 年 int mouth = calendar.get(Calendar.MONTH) + 1;// 月 int day = calendar.get(Calendar.DAY_OF_MONTH);// 几号 int hour = calendar.get(Calendar.HOUR);// 小时 int minute = calendar.get(Calendar.MINUTE);// 分 int second = calendar.get(Calendar.SECOND);// 秒 // 设置制定年月日 calendar.set(2014, 11, 1, 1, 1, 1); year = calendar.get(Calendar.YEAR);// 年 mouth = calendar.get(Calendar.MONTH);// 月 day = calendar.get(Calendar.DAY_OF_MONTH);// 几号 hour = calendar.get(Calendar.HOUR);// 小时 minute = calendar.get(Calendar.MINUTE);// 分 second = calendar.get(Calendar.SECOND);// 秒 System.out.println(year + “=” + mouth + “=” + day + “=” + hour + “=” + minute + “=” + second); // 获取指定格式输出日期 Date date = new Date();// 可以使用时间错 SimpleDateFormat dateFormat = new SimpleDateFormat( “yyyy-MM-dd HH:mm:ss”); String riqi = dateFormat.format(date); System.out.println(riqi); // 获得2010年9月13日22点36分01秒 的Date对象 SimpleDateFormat dateFormat2 = new SimpleDateFormat( “yyyy-MM-dd HH:mm:ss”); Date myDate2 = null; try myDate2 = dateFormat2.parse(“2010-09-13 22:36:01”); } catch (ParseException e) // TODO Auto-generated catch block e.printStackTrace(); } long myie = myDate2.getTime(); long myief=1284388561000L;//后面必须有个L String rename=dateFormat2.format(new Date(myief));
楼主的格式没说清楚,比如说日期,1号的是 01 还是 1
赞(0)
【声明】:本博客不参与任何交易,也非中介,仅记录个人感兴趣的主机测评结果和优惠活动,内容均不作直接、间接、法定、约定的保证。访问本博客请务必遵守有关互联网的相关法律、规定与规则。一旦您访问本博客,即表示您已经知晓并接受了此声明通告。