导航:首页 > 编程语言 > 日期格式java

日期格式java

发布时间:2022-02-06 11:09:54

java日期格式化问题

SimpleDateFormatdateFormat=newSimpleDateFormat("yyy-MM-ddHH:mm:ss");
//时间转字符串
Stringcurrentdate=dateFormat.format(newDate());
//字符串转日期
Stringbefore="2014-11-0411:11:00.0";
Dateafter=dateFormat.parse(before);

不知道你要的是哪种

❷ JAVA中日期格式转换:2012-07-10 00:00:00.000如何转换成2012年07月10日

Java时间格式转换大全

import java.text.*;

import java.util.Calendar;

public class VeDate {

/**
* 获取现在时间
*
* @return 返回时间类型 yyyy-MM-dd HH:mm:ss
*/

public static Date getNowDate() {

Date currentTime = new Date();

SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

String dateString = formatter.format(currentTime);

ParsePosition pos = new ParsePosition(8);

Date currentTime_2 = formatter.parse(dateString, pos);

return currentTime_2;

}

Java是一门面向对象编程语言,不仅吸收了C++语言的各种优点,还摒弃了C++里难以理解的多继承、指针等概念,因此Java语言具有功能强大和简单易用两个特征。Java语言作为静态面向对象编程语言的代表,极好地实现了面向对象理论,允许程序员以优雅的思维方式进行复杂的编程。

❸ JAVA时间转换

String dt="Fri Apr 13 2012 09:20:51 GMT +0800 (China Standard Time)";
dt=dt.replaceAll(" GMT.+$", "");
System.out.println(dt);
SimpleDateFormat pSdf=new SimpleDateFormat("EEE MMM DD yyyy HH:mm:ss",Locale.ENGLISH);
SimpleDateFormat fSdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
System.out.println(fSdf.format(pSdf.parse(dt)));

❹ JAVA 日期格式化的问题

<script language=javascript>
function ShowDateTime(input1,input2)
{
var DateTime1=input1.substr(0,4) + input1.substr(5,2) + input1.substr(8,2) + input1.substr(11,2) + input1.substr(14,2);
DateTime1=showModalDialog('setdatetime.jsp?vDateTime=' + DateTime1, '', 'dialogWidth:15; dialogHeight:22em; status:0;overflow:hidden');
try{
if(DateTime1==null)
return;
else if(DateTime1=="")
return;
else if(DateTime1=="CancelSetDateTime")
return;
else if(DateTime1=="SetDateTimeIsNull")
{
if(input2==1)
formq.fcsj1.value='';
else if(input2==2)
formq.fcsj2.value='';
}
else
{
if(input2==1)
formq.fcsj1.value=DateTime1;
else if(input2==2)
formq.fcsj2.value=DateTime1;
}
}catch(e){}
}
</script>

<%
Date now=new Date();
Date D1=new Date();
Date D2=new Date();
long millDay=0;

int nowHour=now.getHours();
int nowMinute=now.getMinutes();
int nowSecond=now.getSeconds();
millDay=1000*60*60*24;

D1.setTime(now.getTime()-millDay*2);
D2.setTime(now.getTime()+millDay*1);

SimpleDateFormat dateFormat=new SimpleDateFormat("yyyy.MM.dd/HH:mm");
%><font color="#000080"> </font><font color="#000080">发车时间:<input type="text" name="fcsj1" id="fcsj1" size="16" value="<%=dateFormat.format(D1)%>" onfocus="javascript:ShowDateTime(formq.fcsj1.value,1);fcsj1.blur();">
至<input type="text" name="fcsj2" id="fcsj2" size="16" value="<%=dateFormat.format(D2)%>" onfocus="javascript:ShowDateTime(formq.fcsj2.value,2);fcsj2.blur();">

❺ java中的日期格式化怎么做的

importjava.text.SimpleDateFormat;
importjava.util.Date;

/**
*日期格式化问题
*
*@authorAdministrator
*
*/
publicclassDateFormatTest{
publicstaticvoidmain(String[]args){
Dated=newDate();
//"yyyy-MM-ddHH/mm/ss","yyyy-MM-ddHH时mm分ss秒",
SimpleDateFormatformatter=newSimpleDateFormat("yyyy-MM-ddHH时mm分ss秒");
System.out.println(formatter.format(d));
}

}

❻ java时间转换

java中毫秒转日期:
//毫秒转换为日期
public static void main(String[] args) {
DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
long now = System.currentTimeMillis();
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(now);
System.out.println(now + " = " + formatter.format(calendar.getTime()));
// 日期转换为毫秒 两个日期想减得到天数
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String start="2011-09-20 12:30:45";
String end ="2011-10-20 6:30:00";
//得到毫秒数
long timeStart=sdf.parse(start).getTime();
long timeEnd =sdf.parse(end).getTime();
//两个日期想减得到天数
long dayCount= (timeEnd-timeStart)/(24*3600*1000);
System.out.println(dayCount);
}

❼ Java日期转换问题

YYYY表示的是当前时间所在的年份的一月一号所在的那个星期中第一天的日期也就是星期日那一天的日期。2016年1月1号所在的星期的第一天是2015年12月27号。

❽ java日期格式化

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

public class Test {
public static void main(String[] args) {
final String dayNames[] = { "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六" };

SimpleDateFormat sdfInput = new SimpleDateFormat("yyyy年MM月dd日");

Calendar calendar = Calendar.getInstance();
Date date = new Date();

calendar.setTime(date);
int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);

System.out.println(sdfInput.format(date) + " " + dayNames[dayOfWeek - 1]);
}
}

❾ Java日期格式转换

借助SimpleDateFormat来格式化。
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
SimpleDateFormat sdf1=new SimpleDateFormat("yyyy/M/d");
String d=sdf.format(sdf1.parse("2019/9/8"))

❿ 如何将JAVA DATE类型的日期 转换成指定格式类型的 (如:YYYY-MM-DD) 的 DATE类型数据

Date类型并没有格式,只有转换成String格式的时候让格式化显示。

new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")format(new Date());

Calendar calendar = Calendar.getInstance();

int year = Integer.parseInt(datetime.substring(0,4));

int month = Integer.parseInt(datetime.substring(5,7));

int date = Integer.parseInt(datetime.substring(8,10));

int hour = Integer.parseInt(datetime.substring(11,13));

int minute = Integer.parseInt(datetime.substring(14,16));

//int second = Integer.parseInt(datetime.substring(17,19));

if(calendar.get(Calendar.YEAR)>year){

int y = calendar.get(Calendar.YEAR)-year;

(10)日期格式java扩展阅读:

Date类可以在java.util包中找到,用一个long类型的值表示一个指定的时刻。它的一个有用的构造函数是Date(),创建一个表示创建时刻的对象。getTime()方法返回Date对象的long值。

import java.util.*;

public class Now {

public static void main(String[] args) {

Date now = new Date();

long nowLong = now.getTime();

System.out.println("Value is " + nowLong);

阅读全文

与日期格式java相关的资料

热点内容
数学奇迹神奇运算法 浏览:359
大厂的程序员的水平如何 浏览:700
遗传算法入门经典书籍 浏览:878
源码炮台脚本 浏览:620
在位编辑命令 浏览:347
曲式分析基础教程pdf 浏览:14
php生成静态html页面 浏览:964
怎么分割pdf 浏览:812
压缩垃圾报警器 浏览:629
小公司一般都用什么服务器 浏览:968
java获取时间gmt时间 浏览:820
为什么csgo一直连接不到服务器 浏览:504
安卓登ins需要什么 浏览:836
机器人算法的难点 浏览:226
全自动化编程 浏览:727
程序员高薪限制 浏览:693
压缩图片压缩 浏览:75
美国发明解压魔方 浏览:302
电脑怎么备案网上服务器 浏览:515
旅行商问题Python写法 浏览:954