请教各位高手一个简单问题,急

wuyan55 2003-02-11 03:43:37
date型中小时是从0-23 现在我要返回一个28:34:45的date型数据,请问应该怎么做,请给个例子
...全文
107 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
hayai 2003-02-11
  • 打赏
  • 举报
回复
写一个Interval Class.Interval stands for a time interval between two Dates. we have one, like the following.
import java.util.*;

/**
* <p>Description: </p>
* Represents an interval between two time points on the time line.<br>
* One of the two major tasks fulfilled by this Class is to calculate the time
* escaped between two time points in milisecond, second, minute, and hour.
* The other calculation this Class does is to figure out the years, months,
* and days between two Dates according to java.util.Calendar.
* Even though the values are, but the intepretation is ambiguous.
* For instance, if we have an Inteval says there are 1 year, 2 months and
* 20 days diferrent, how many days is that year, and how many days are those
* two months excatly?
* The answers are unknown.
* <p>Copyright: Copyright (c) 2003</p>
* @version 2.0
*/

public class Interval
{
////////////
/* Fields */
////////////

/**
* Long representation of two time points in <b>ms</b>.<br>
*/
private long m_lngMilliSecond = 0;

// Must be positive
protected int m_intDayDiff, m_intMonthDiff, m_intYearDiff;

//////////////////
/* Constructors */
//////////////////

/**
* <b>Note:</b>
* If an Interval Object is constructed from this Constructor,
* getDayDiff(), getMonthDiff(), getYearDiff() will NOT be able to invoke.
*
* @throws IllegalArgumentException if intInterval is negative.
*/
public Interval(long intInterval)
{
if (intInterval < 0)
{
throw new IllegalArgumentException("Interval can NOT be negative.");
}
m_lngMilliSecond = intInterval;
m_intDayDiff = -1;
}

/**
* @throws IllegalArgumentException if the begin Date is NOT before the
* end Date.
*/
public Interval(Date begin, Date end)
{
m_lngMilliSecond = end.getTime() - begin.getTime();
if (m_lngMilliSecond < 0)
throw new IllegalArgumentException("Begin Date is NOT before the End Date.");

DateDealer dd = DateDealer.getInstance();

m_intDayDiff = dd.getDay(end) - dd.getDay(begin);
m_intMonthDiff = dd.getMonth(end) - dd.getMonth(begin);
m_intYearDiff = dd.getYear(end) - dd.getYear(begin);

if (m_intDayDiff < 0)
{
m_intDayDiff += dd.getDaysOfMonth(begin);
m_intMonthDiff--;
}

if (m_intMonthDiff < 0)
{
m_intMonthDiff += 12;
m_intYearDiff--;
}
}

/**
* @throws IllegalArgumentException if the begin Date is NOT before the
* end Date.
*/
public Interval(Calendar begin, Calendar end)
{
this(end.getTime(), begin.getTime());
}

//////////////////////////
//plus and minus methods//
//////////////////////////

/**
* Adds a certain time interval to this one.
* This method will effect the value of this Interval Object instance.<br>
* <b>Note:</b>
* If this method is invoked,
* getDayDiff(), getMonthDiff(), getYearDiff() will NOT be able to invoke.
*/
public Interval plus(Interval src)
{
m_lngMilliSecond += src.m_lngMilliSecond;
return this;
}

/**
* Substracts a certain time interval to this one.
* The method will effect the value of this Interval Object instance.<br>
* <b>Note:</b>
* If this method is invoked,
* getDayDiff(), getMonthDiff(), getYearDiff() will NOT be able to invoke.
*/
public Interval minus(Interval src)
{
m_lngMilliSecond -= src.m_lngMilliSecond;
return this;
}

/**
* This method will NOT effect the value of this Interval Object instance.
*/
public Date plus(Date src)
{
return new Date(src.getTime() + m_lngMilliSecond);
}

/**
* This method will NOT effect the value of this Interval Object instance.
*/
public Date minus(Date src)
{
return new Date(src.getTime() - m_lngMilliSecond);
}

///////////////
//Get Mothods//
///////////////

public long getMillis()
{
return m_lngMilliSecond;
}

public int getSecond()
{
return (int)(m_lngMilliSecond / 1000);
}

public int getMinute()
{
return (int)(m_lngMilliSecond / 1000 / 60);
}

public int getHour()
{
return (int)(m_lngMilliSecond / 1000 / 60 / 60);
}

/**
* <b>Note:</b>
* It makes more sense to use this method with getMonthDiff() and
* getYearDiff().
* @throws UnsupportedOperationException if the answer is not clear.
* Such situation will happen in two cases:<br>
* 1. The Interval Object instance is constructed from Interval(long).<br>
* 2. The plus(Interval) and/or minus(Interval) has been invoked.<br>
*/
public int getDayDiff()
{
if (m_intDayDiff < 0)
throw new UnsupportedOperationException("Unclear answer.");
return m_intDayDiff;
}

/**
* <b>Note:</b>
* It makes more sense to use this method with getYearDiff().
* @throws UnsupportedOperationException if the answer is not clear.
* Such situation will happen in two cases:<br>
* 1. The Interval Object instance is constructed from Interval(long).<br>
* 2. The plus(Interval) and/or minus(Interval) has been invoked.<br>
*/
public int getMonthDiff()
{
if (m_intDayDiff < 0)
throw new UnsupportedOperationException("Unclear answer.");
return m_intMonthDiff;
}

/**
* @throws UnsupportedOperationException if the answer is not clear.
* Such situation will happen in two cases:<br>
* 1. The Interval Object instance is constructed from Interval(long).<br>
* 2. The plus(Interval) and/or minus(Interval) has been invoked.<br>
*/
public int getYearDiff()
{
if (m_intDayDiff < 0)
throw new UnsupportedOperationException("Unclear answer.");
return m_intYearDiff;
}
}
wuyan55 2003-02-11
  • 打赏
  • 举报
回复
而且要求一定返回一个date型数据
wuyan55 2003-02-11
  • 打赏
  • 举报
回复
因为要算加班的问题,一个加班日是有28:23:34的
希偌 2003-02-11
  • 打赏
  • 举报
回复
不行
String s="2003-2-21 28:22:22";
java.text.SimpleDateFormat df=new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try{java.util.Date d=df.parse(s);System.out.println(df.format(d));}catch(Exception e){System.out.println(e.toString());}
上面这段得到的结果为
2003-2-22 04:22:22
系统自动进位,日期自动加上1,而小时数减少24
iamqqmyheart 2003-02-11
  • 打赏
  • 举报
回复
非法的date


可用String代替


可我不明白你的目的.
hayai 2003-02-11
  • 打赏
  • 举报
回复
我今天28时34分45秒回答你。
内容概要:本文系统研究了开关频率大于谐振频率(fs>fr)工况下,移相混合控制LLC谐振变换器在低压增益区域的工作特性,深入分析其在变频与移相结合控制模式下的调制机理、工作模态划分及损耗分布规律。通过Simulink平台构建高保真仿真模型,对变换器在不同负载和输入条件下的电压增益、转换效率、关键器件电压电流应力等性能指标进行了全面仿真验证,重点探讨了其在低增益区间的软开关实现能力与效率优化潜力,旨在提升LLC变换器在宽范围输入输出应用中的动态响应与能源转换效率。; 适合人群:从事电力电子变换器设计、高频电源开发及相关领域的高校研究生、科研院所研究人员及企业研发工程师,要求具备扎实的电路理论基础、电力电子技术知识以及一定的Simulink仿真能力。; 使用场景及目标:①深入理解LLC谐振变换器在fs>fr条件下采用移相混合控制的内在工作机理与模态转换过程;②掌握利用Simulink搭建复杂谐振变换器精确仿真模型的方法与技巧;③分析并优化低压增益区的增益特性与损耗构成,为设计高效率、高功率密度的软开关电源提供理论依据和数据支持; 阅读建议:建议读者结合文中所述仿真模型,亲自复现仿真过程,重点观察不同控制参数(如移相比、开关频率)对电压增益曲线和关键波形的影响,并对比传统变频控制策略,深入探究混合控制在拓宽调压范围、提升轻载效率方面的优势,从而深化对现代高效谐振电源设计的理解。
内容概要:本文提出了一种基于粒子群优化算法(PSO)的配电网光伏储能双层优化配置模型,以IEEE33节点系统为标准算例,实现光伏发电单元与储能系统的协同选址与定容优化。该模型采用双层架构设计,上层以投资成本、运行经济性及网络损耗最小为目标优化设备配置方案,下层通过潮流计算评估系统在不同负荷场景下的运行性能,综合考虑电压稳定性、供电可靠性及可再生能源消纳能力,最终通过Matlab编程实现完整求解流程,为高渗透率分布式电源接入背景下的配电网规划提供了有效的技术支撑。; 适合人群:具备电力系统分析基础和Matlab编程能力的研究生、高校科研人员及从事新能源并网、智能配电网规划与优化的工程技术人员。; 使用场景及目标:①研究含高比例光伏接入的配电网规划与运行协同优化问题;②掌握双层优化建模方法与粒子群算法在复杂电力系统问题中的应用技巧;③为实际工程中分布式光伏与储能系统的科学选址与容量配置提供理论依据与仿真验证平台。; 阅读建议:建议读者结合Matlab代码深入理解双层迭代求解机制,重点关注算法收敛性分析、参数敏感性测试,并可通过更换初始种群、调整权重因子或引入其他标准测试系统(如IEEE69节点)进行对比实验,进一步验证所提模型的普适性与鲁棒性。

62,622

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧