Tag: 日期

java比较两个日期

我想比较两个日期并检查日期是否已过期。 这是我使用的代码: SimpleDateFormat sdf = new SimpleDateFormat(“yyyy-MM-dd hh:ss:ii”); Date date1 = sdf.parse(“20012-10-4 10:15:25”); Date date2 = sdf.parse(“2013-10-4 10:15:25”); if(date1.equals(date12)){ System.out.println(“Both are equals”); } 我想查看两个日期,但没有成功。 我也试着这样检查: if(date1 >= date2){ System.out.println(“Both are not equals”); } 但它也没有用。

如何在Java中按语言环境格式化日期?

我需要将日期格式化为具有多种语言的应用程序,格式化日期的最佳方式是什么,因为每个国家/地区都有不同类型的日期格式,因此可以按区域设置格式化日期吗?

如何以与String相同的格式获取Date

我希望在向现有Date对象添加几个月后,以yyyy-mm-dd格式获取包含Date的Date对象。 使用DateFormat对象我尝试过这种方式,但它没有按我的意愿提供输出。 如何在Java中获取此日期格式? 我的代码 – Calendar c=Calendar.getInstance(); DateFormat sdf=new SimpleDateFormat(“yyyy-mm-dd”); Date d=cal.getTime(); c.add(Calendar.MONTH,10); Date newd1=c.getTime(); String news=sdf.format(newd1); Date dnew=(Date)sdf.parse(news); 字符串新闻的格式为yyyy-mm-dd,但是当我在该字符串上使用parse时,它会生成Date对象,格式为“Thu Jan 21 00:14:00 IST 2016”。 如何在上面的代码中使用String news以“yyyy-mm-dd”的forms获取Date对象。

如何在Java中获取特定年份的所有星期日?

我正在认真寻找这个代码…我是新程序员。 实际上我想用旗帜制作所有日期,这些日期都是特定年份的星期日。 拜托,我急切地等待你的回应….

JTable中的JSpinner(时间)

我正试图在JTable中实现一个JSpinner,它在第一次看起来很有效但在失去了单元格的焦点之后,编辑的单元格被设置为“Thu Jan 01 + time + UTC 1970”时间正在设置正确。 如何从时间中删除日期? 这是我的洞SpinnerEditor.class,添加了一些评论。 代码: public SpinnerEditor(String timeFormat) { super(new JTextField()); // Default Time I want to Display (1 Hour) Time date = new Time(3600000); SpinnerDateModel timeModel = new SpinnerDateModel(date, null, null,Calendar.MINUTE); spinner = new JSpinner(timeModel); editorDate = new JSpinner.DateEditor(spinner, timeFormat); spinner.setEditor(editorDate); editorDate = ((JSpinner.DateEditor)spinner.getEditor()); // println result : […]

如何确定Java之间的现在和任意未来日期之间的时间

我目前正在尝试确定两个日期之间的时间量(其中一个是当前日期/时间,另一个是任意的未来日期)。 我只使用原生Java和Android API,但我遇到GregorianCalendar的一些问题。 到目前为止,我的代码可以在下面看到,但我遇到的问题是两个日期之间的时间非常不准确。 你可以看到我在这个例子中将未来的日期设定为圣诞节,但它告诉我那时已有超过62天,这显然是错误的。 date = new GregorianCalendar(); currentTime = date.getTimeInMillis(); calendar = new GregorianCalendar(); calendar.set(2011, 12, 25, 0, 0, 0); long difference = calendar.getTimeInMillis()-currentTime; long x = difference / 1000; seconds = x % 60; x /= 60; minutes = x % 60; x /= 60; hours = x % 24; x /= […]

给出错误日期的Java Date()

我有一个简单的方法,应该获取当前日期,将其放入某种格式,然后将其作为String返回。 到目前为止一切都很好(最后一次尝试在1月31日左右),但出于某种原因,当我今天尝试它时它返回字符串“2013-02-43”。 现在显然2月份还没有43天,我不知道它为什么要回归这个。 我已经到处寻找解决方案,但它们似乎都不符合我所遇到的具体问题。 这是代码: public String getDate(){ DateFormat dateFormat = new SimpleDateFormat(“YYYY-MM-DD”); Date date = new Date(); return dateFormat.format(date); } 只是为了记录我尝试使用Calendar.getInstance()等具有相同的结果。 有趣的是,当我尝试 get(Calendar.DAY_OF_MONTH) 它回来了12,所以某些地方的数字是正确的,但两者之间出现了问题。 谢谢

在Java中将毫秒字符串转换为日期

我有一个字符串x =“1086073200000”。 这基本上是毫秒,我需要转换为Date。 转换我正在使用 DateFormat formatter = new SimpleDateFormat(“dd/MM/yyyy”); long tempo1=Long.parseLong(x); System.out.println(tempo1); // output is 86073200000 instead of the whole thing long milliSeconds=1346482800000L; Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(milliSeconds); System.out.println(formatter.format(calendar.getTime())); 问题是当我将字符串x转换为long时,由于long的大小限制,一些数字会消失。 如何保留整个String。 谢谢。

用Java解析格式“2010年1月10日”的日期? (有序数指标,st | nd | rd | th)

我需要用Java解析格式“2010年1月10日”的日期。 我怎样才能做到这一点? 如何处理序数指标 , st , nd , rd或th尾随日期数?

时间不会在Applet中重新绘制

我有一个小问题,但我不知道要解决它。 我创建了简单的Applet,其中应该是简单的数字时钟。 我正确地创建了所有方法,但重绘方法不会重新绘制我的applet。 你能检查我的代码并说出错误的地方吗? 谢谢。 public class DigitalClock extends JApplet implements Runnable { private Thread timeThread; Date date = new Date(); public void start() { timeThread = new Thread(this, “Clock”); timeThread.start(); } @Override public void stop() { if (timeThread == null) { return; } timeThread = null; } @Override public void run() { while (timeThread […]