Questions tagged [apache-commons-dateutils]

A helper class from Apache commons-lang used for manipulations of Dates or Calendars.

A helper class from Apache commons-lang used for manipulations of Dates or Calendars.

The project Home Page: http://commons.apache.org/proper/commons-lang/.

18 questions
9
votes
4 answers

Convert Date String into Epoch in Java

Is there a way to convert a given Date String into Milliseconds (Epoch Long format) in java? Example : I want to convert public static final String date = "04/28/2016"; into milliseconds (epoch).
Ashley
  • 441
  • 2
  • 8
  • 27
5
votes
5 answers

Find next quarter end date given previous quarter end date using Java

I am having quarter end date of last quarter let it be 30-09-20 , the requirement is to find end date of next quarter i.e 31-12-20. I am using below code to do the same but is it giving wrong output in some scenarios. This solution should be correct…
Loren
  • 320
  • 1
  • 10
  • 25
5
votes
2 answers

Apache DateUtils truncate for WEEK

I'm using Apache commons-lang3 DateUtils.truncate(Calendar calendar, int field) method to 'cut off' unnecessary fields of a Calendar object. Now when the field parameter gets the value of Calendar.WEEK_OF_MONTH, it throws…
Sleeper9
  • 1,707
  • 1
  • 19
  • 26
2
votes
2 answers

DateUtils.parseDate exception

I can't seem to get this to work, it says Unknown pattern character - "T" Unable to parse the date 2011-07-22T12:01:34.9455820 Date theDate = DateUtils.parseDate(notif.dateStr, new String[]{"yyyy-MM-ddTHH:mm:ss.S"}); This won't work either(which is…
spentak
  • 4,627
  • 15
  • 62
  • 90
2
votes
1 answer

How to show future date using DateUtils

I'm creating app. It's a news list where on every news I need to show date, e.g. 9 hours ago or 1 month ago and so on. Also I have future news, so I need also to show e.g. after 1 month. So I'm using DateUtils.getRelativeTimeSpanString() for this…
1
vote
2 answers

Apache date utils parseDateStrictly method dosen't work properly

DateUtils.parseDateStrictly("28 Sep 2018" , "dd MMMM yyyy") The format of the above date should be dd MMM yyyy (MMM denotes shorter month) , but MMMM also parses shorter month which causes invalid parsing. I am already using parseDateStrictly…
H.Aadhithya
  • 205
  • 1
  • 12
1
vote
2 answers

date format using apache lang DateUtil fails

i was trying to convert date in string format to date using DateUtils. Following are my expected date format, private static final String[] EXPECTED_DATE_FORMAT = {"yyyy-MM-dd","dd-MM-yyyy","dd-MMM-yyyy",}; And I ran the test against following…
Kajal
  • 709
  • 8
  • 27
0
votes
0 answers

Using DateUtils.parseDate method, want to specify a specific TimeZone, but can't

When I use the DateUtils.parseDate method, I need to specify a special time zone, such as ZoneId.of("America/New_York"), to parse the special string into a Date object. Because I like this framework very much, and I hope it becomes more usable. I…
0
votes
1 answer

Unable to parse date YYYY-MM-DDThh:mm:ssTZD from string using DateUtils.parseDate

Having date as string: "2021-09-11T12:02:50-06:00Z". Want to convert to java.util.Date using apache DateUtils: public static Date toDate (String dateString) throws ParseException { String DATETIME_FORMAT =…
0
votes
3 answers

Problems with parsing dates using DateUtils

I am trying to parse various slightly different date strings for an Android application. Two examples are: Thu, 20 Aug 2020 13:30:16 +0000 Wed, 19 Aug 2020 15:28:47 GMT Here is how I tried parsing these Strings: Date pubDate =…
Florian Baierl
  • 2,378
  • 3
  • 25
  • 50
0
votes
1 answer

DateUtils.getRelativeTimeSpanString Returning a Formatted Date String Instead of "Hours/Minutes Ago"

I'm having fierce problems trying to get DateUtils.getRelativeTimeSpanString to return what it's supposed to in Android. I've been through every similar question here and none of the solutions posted are working or relevant. Here's my…
0
votes
1 answer

Apache DateUtils parses random date

Date date = DateUtils.parseDate("1243334-03332-284555", "yyyy-MM dd"); The Apache DateUtils was able to parse the above random date even though specifying the date format. Does anyone know what is the reason behind it ?? For my use case, the above…
Abhilash
  • 196
  • 11
0
votes
3 answers

Round java.util.Date to end of day

I want to round a java.util.Date object to the end of the day, e.g. rounding 2016-04-21T10:28:18.109Z to 2016-04-22T00:00:00.000Z. I saw Java Date rounding, but wasn't able to find something compareable for the end of the day. It also is not the…
0
votes
0 answers

how to round off a date which is in UTC?

I am trying to round off a date object to the nearest date. for eg: let date = 12th march 4:00 UTC (offset = 4:00). I want to round the date to the nearest date after converting it into local time with the Timezone(TZ) information provided. So now,…
Nikhil
  • 1,279
  • 2
  • 23
  • 43
0
votes
2 answers

Apache DateUtils truncate day of month

I would like to create a DateHelper class and for that I'm using DateUtils from Apache Commons Lang 2.6. I'm having problems understanding the result returned when extract field from a date. Here is my test class which extract the day of month…
jerome
  • 2,029
  • 4
  • 38
  • 58
1
2