Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I wrote a java utility function to convert yyyy/mm/dd as follows

public static long gettimestamp(String dateString) {
  SimpleDateFormat df = new SimpleDateFormat("yyyy/mm/dd");
  Date date;
  try {
  date = df.parse(dateString);
  } catch (java.text.ParseException e) {
    return 0;
  }
  long epoch = date.getTime();
  return (epoch / 1000);
}

On passing 2014/06/12 - it gives 1389465360 (=Jan 11, 2014) which is wrong. Am I passing format in wrong way ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
2.0k views
Welcome To Ask or Share your Answers For Others

1 Answer

You should uppercase the M. Lowercase m stands for minutes, while uppercase stands for month. Here's the documentation.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...