java.util.date

Bug in jdk8 date-conversion?

被刻印的时光 ゝ 提交于 2020-02-19 12:35:27
问题 I was writing some testcode for java-8 conversion between java.util.Date and java.time.LocalDateTime , and discovered an anomaly seems to occur in the hour after the transition from normaltime-to-summertime, when the year is 2038 or higher. I just wanted to know if this is a bug in jdk8, or if I am doing something wrong? Note: I am on Windows-7, 64-bit jdk, so should not be affected by the 2038-unix bug, which would have a much worse effect. Here my demo-code: package conversiontest; import

Counting number of days of a particular month when given a duration

眉间皱痕 提交于 2020-02-08 11:18:11
问题 A duration is given. Ex: Jan 15-March 15 I want to count the number of days which belongs to each month, in that given duration. In this example, number of days of January in that duration; 15 number of days of February in that duration; 28 number of days of March in that duration; 15 I'm looking for a solution other that traversing through each date of the duration and checking if Date.getMonth() = "Month I want to check against" Is there an easier way of doing this using methods in Java

Counting number of days of a particular month when given a duration

拈花ヽ惹草 提交于 2020-02-08 11:17:50
问题 A duration is given. Ex: Jan 15-March 15 I want to count the number of days which belongs to each month, in that given duration. In this example, number of days of January in that duration; 15 number of days of February in that duration; 28 number of days of March in that duration; 15 I'm looking for a solution other that traversing through each date of the duration and checking if Date.getMonth() = "Month I want to check against" Is there an easier way of doing this using methods in Java

I can't import java.util.date in activity

半世苍凉 提交于 2020-01-16 04:17:19
问题 In my project I need to to use current date and time. For this I'm importing java.util.Date. This import is working fine few hours ago. But I have an error in R file ( r cannot resolve ) and this error is because of some xml mistake. When I resolved that issue and sync project again that error is gone. But after that I cannot able to import (java.util.Date , java.util.Calendar) in any of my project. I tried to import this in my newly created project. But still not found java.util.Date. Even

Get date representation in seconds?

南楼画角 提交于 2019-12-29 05:51:06
问题 I am using an API which requires a date parameter as a number of seconds, an int . My problem is that I currently store this time in java.util.date and I was wondering if there is some way to convert the java.util.date variable to seconds so that I can fit it into the int parameter which the API requires? 回答1: import java.util.Date; ... long secs = (new Date().getTime())/1000; ... Please see - http://docs.oracle.com/javase/6/docs/api/java/util/Date.html#getTime() 回答2: java.util.Date.getTime()

java.util.Date: seven days ago

穿精又带淫゛_ 提交于 2019-12-29 04:30:15
问题 I have a report created in Jasper Reports which ONLY recognizes java.util.Date's (not Calendar or Gregorian, etc). Is there a way to create a date 7 days prior to the current date? Ideally, it would look something like this: new Date(New Date() - 7) UPDATE: I can't emphasize this enough: JasperReports DOES NOT RECOGNIZE Java Calendar objects. 回答1: From exactly now: long DAY_IN_MS = 1000 * 60 * 60 * 24; new Date(System.currentTimeMillis() - (7 * DAY_IN_MS)) From arbitrary Date date : new Date

How can I create a Date object with a specific format

假如想象 提交于 2019-12-28 07:03:06
问题 String testDateString = "02/04/2014"; DateFormat df = new SimpleDateFormat("dd/MM/yyyy"); Date d1 = df.parse(testDateString); String date = df.format(d1); Output String: 02/04/2014 Now I need the Date d1 formatted in the same way ( "02/04/2014" ). 回答1: If you want a date object that will always print your desired format, you have to create an own subclass of class Date and override toString there. import java.text.SimpleDateFormat; import java.util.Date; public class MyDate extends Date {

Java - Calendar / Date difference - Find difference down to seconds

眉间皱痕 提交于 2019-12-25 07:26:37
问题 Trying to make a little Countdown program in Java. I am working on the finding the difference between the dates part of the app, and for some reason I am only getting the days. I want the days, hours, minutes, and seconds. I am not sure why my calculation is just being rounded to an even integer... 163 in this example, and not 163.xx? Here is my code: import java.util.Date; import java.util.Calendar; import java.util.GregorianCalendar; public class CalcData { Calendar cal1; Date today; public

Java.util.date get the actual date at client timezone

末鹿安然 提交于 2019-12-25 03:22:28
问题 Searching up and down, right and left - don't find simple answer to this question: I have java.util.Date instance, which get its value from mySQL. Also I have time-zone code of the logged-in user. I need to get the actual time at user time-zone. For example: My server-machine time-zone is GMT+2. My date value in DB is: 2017-02-09 16:38:58.000 According to my server-machine-time-zone I get it into date instance as: 2017-02-09T16:38:58.000+0200 Now I need to know what to do if: In case, for

Take date input from user and save it as date in java

十年热恋 提交于 2019-12-24 07:36:28
问题 I'm trying to take input from user in (dd/mm/yy) format, save it in same format and pass it with getter, setter to another class. I have tried this way: This is what I have tried: public static void main(String[] args) { Scanner input = new Scanner(System.in); SimpleDateFormat myFormat = new SimpleDateFormat("dd MM yyyy"); Guest gstObject = new Guest(); try { System.out.println("Enter check-in date (dd/mm/yy):"); String cindate = input.next(); Date date1 = myFormat.parse(cindate); gstObject