Any idea why i'm always getting "Sat 17th" date (Calendar) - java? -


 public static void main(string[] args) {    jsonweathertime time = new jsonweathertime();    string date = time.formatdate(long.valueof(1454691600));  //todays date     system.out.println(date);    }   private string formatdate(long milliseconds){     stringbuffer datebuffer = new stringbuffer();     calendar     calendar = calendar.getinstance();     calendar.settimeinmillis(milliseconds);     switch(calendar.get(calendar.day_of_week)){     case calendar.monday: datebuffer.append("mon, ");     break;     case calendar.tuesday:datebuffer.append("tue, ");     break;     case calendar.wednesday:datebuffer.append("wed," );     break;     case calendar.thursday:datebuffer.append("thur, ");     break;     case calendar.friday:datebuffer.append("fri, ");     break;     case calendar.saturday:datebuffer.append("sat, ");     break;     case calendar.sunday:datebuffer.append("sun, ");     break;     default:datebuffer.append("n/a");   }   string day_of_week = string.valueof(calendar.get(calendar.day_of_month));     if(day_of_week.equals("1") | day_of_week.equals("21") | day_of_week.equals("31") ) day_of_week += "st";     else if(day_of_week.equals("2") | day_of_week.equals("22") ) day_of_week += "nd";     else if(day_of_week.equals("3") | day_of_week.equals("23")) day_of_week += "rd";     else day_of_week += "th";  //log.d("jsonparse", "the value of date issssss" + day_of_week);   datebuffer.append(day_of_week);   return datebuffer.tostring();  } 

i'm parsing json weather data openweathermap api, , no matter value parse date (given in milliseconds through json), calendar returns date of sat 17th. i'm not entirely familiar working dates, json returns millsecond string in unix time, , if pass in todays date (1454691600), string should read (fri, 6th), though returns (sat, 17th). idea i'm doing wrong here?

the value 1454691600 in seconds, not milliseconds.

date date = new date(1454691600 * 1000l); simpledateformat datefmt = new simpledateformat("eee, d"); system.out.println(datefmt.format(date)); // prints: fri, 5  system.out.println(date); // prints: fri feb 05 12:00:00 est 2016 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -