3

According to picture below, when I use item.takendate to SimpleDateFormat

I got "January 2016" instead of "January 2017"

what happen here? please advice.

enter image description here

Edit

However, when I use cdate parse back to Date it value is changed from 1st January to 2nd January

enter image description here

Ole V.V.
  • 81,772
  • 15
  • 137
  • 161
Jongz Puangput
  • 5,527
  • 10
  • 58
  • 96
  • It looks like `2017` in your image. – Aditya Jan 02 '18 at 14:51
  • Looks like your camera is saving file with wrong date, so is the image's metadata corrupted. – Alex2452 Jan 02 '18 at 14:53
  • @Heisen-Berg it's 2017, but when I use SimpleDateFormat to format date result is 2016 – Jongz Puangput Jan 02 '18 at 14:54
  • @Hubertoss is it related to camera file saving ?? – Jongz Puangput Jan 02 '18 at 14:55
  • 1
    Well, I spotted that the picture is saved with date of 2017/01/01 in the name, if they are saved externally then I would check it. Otherwise, if you save them yourself then it is you should change "YYYY" to "yyyy". YYYY stands for WEEK_OF_YEAR in Java 8 and is synchronized with the week numbers. – Alex2452 Jan 02 '18 at 15:02
  • @Hubertoss all this data fetch from system only no update, thank you anyway – Jongz Puangput Jan 02 '18 at 15:04
  • Possible duplicate of ["EEE MMM dd HH:mm:ss ZZZ yyyy" date format to java.sql.Date](https://stackoverflow.com/questions/43933597/eee-mmm-dd-hhmmss-zzz-yyyy-date-format-to-java-sql-date) – Ole V.V. Jan 03 '18 at 14:40
  • As an aside consider throwing away the long outmoded and notoriously troublesome `SimpleDateFormat` and friends, and adding [ThreeTenABP](https://github.com/JakeWharton/ThreeTenABP) to your Android project in order to use `java.time`, the modern Java date and time API. It is so much nicer to work with. – Ole V.V. Jan 03 '18 at 14:43

1 Answers1

21

When using SimpleDateFormat, YYYY and yyyy have different meanings! You almost certainly want to use yyyy (actual year) instead of YYYY (week year).

Todd
  • 30,472
  • 11
  • 81
  • 89
  • 3
    Solved, thank you, I will accept answer when it allow. – Jongz Puangput Jan 02 '18 at 14:57
  • 7
    A bit of explanation: the first of january 2017 may have week number 52 of "week" year 2016; and the following Monday (generally) then is week 1 of (week and calendar) year 2017. – Joop Eggen Jan 02 '18 at 15:07