0

I want to use date as a parameter with a url call in the following format YYYYMMDDHHMMSS.When i checked java Date it is in how can i do that in java ? or i have to give time manually using the below code?

public static long start_date=20140423101010L;

the above variable has a date from the year 2014 month 04, date 23, and time hour :10., min:10 and sec :10. I want this time in the above format (YYYYMMDDHHMMSS) to JodaTime.

Is it possible to do that?

sarath
  • 455
  • 1
  • 11
  • 26
  • There is [this](http://stackoverflow.com/questions/4216745/java-string-to-date-conversion) and [that](http://stackoverflow.com/questions/4772425/format-date-in-java) and a multitude of other existing questions. – Oleg Estekhin Jun 20 '14 at 10:16
  • @OlegEstekhin Your comment would be more useful if made via that "close" link found beneath the answer's tags. – Basil Bourque Jun 21 '14 at 01:22

1 Answers1

4

Try

DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyyMMddHHmmss");
DateTime dateTime = formatter.parseDateTime(String.valueOf(start_date));
filip
  • 414
  • 3
  • 14
  • may i ask you one more doubt please.. How to split Datetime in this pattern by half? – sarath Jun 20 '14 at 10:02
  • I don't understand. Give me an example please. – filip Jun 20 '14 at 10:05
  • i will explain. i have time period start_date and end_date. start_date is the above date and end_date is in 1 month time. i am using this date to fetch some data from an API with in the time limit. but if i am getting more products i want to take only from 15 days period data. for that i want to divide the time period by half.so start date will be 15 of the month instead of 01 st of the month. is it possible in JodaTime? – sarath Jun 20 '14 at 10:11
  • You can add days on your DateTime object. Read [this post](http://stackoverflow.com/questions/16461361/add-one-day-into-joda-time-datetime). Read it carefully. When adding days you are not changing your object but instead you are creating a new one. Hope this helps. – filip Jun 20 '14 at 10:20
  • To find the difference in days read [this post](http://stackoverflow.com/questions/3802893/number-of-days-between-two-dates-in-joda-time). Read the second answer, the community said the first answer is wrong. – filip Jun 20 '14 at 10:26