I have all sorts of methods ive made over the years for making date strings, but they dont seem to work now. Everytime I pass in ms they come up with 1970.
but if I pass it into any of my methods I always get 18/01/1970. Am I doing somethign wrong or has there somehow been a new bug introduced into the Data class?
public static String getDateString(Date d)
{
if (d==null)
{
_("*warning* date passed in was null, we will assume that this is 'now' and make a new one");
d= new Date();
}
//formulate this date objects
SimpleDateFormat df = new SimpleDateFormat();
//we want: 2016-11-21T15:47:21+00:00
// String dateString = df.format("yyyy-MM-dd hh:mm:ss a", d);
df.applyPattern("yyyy-MM-dd hh:mm:ss a");//PROBABLY WRONG AFTER CN1 CONVERSION
String dateString = df.format( d);
/// _("dateString is ->"+dateString);
return dateString.toString();
}
//takes a date object in and returns a string like 19/09/2011
public static String getDateString_(Date d)
{
Calendar calendar = null;
calendar = Calendar.getInstance();
calendar.setTime(d);
String day = calendar.get(Calendar.DAY_OF_MONTH)+"";
String month = (calendar.get(Calendar.MONTH)+1)+""; //month starts at 0 in java
if (month.length()==1)
{
month="0"+month; // getthe zero before or it looks odd
}
String year = calendar.get(Calendar.YEAR)+"";
return day+"/"+month+"/"+year;
}
public static String getDateString__(Date date)
{
Calendar cal = Calendar.getInstance();
cal.setTime(date);
int year = cal.get(Calendar.YEAR);
int month = cal.get(Calendar.MONTH);
int day = cal.get(Calendar.DAY_OF_MONTH);
String writeme = day+"/"+month+"/"+year;
//old way was this, so we cna test
//REMOVE THIS, ONLY PUT IT BACK IN FOR TESTING BACKWARDS
//OLD WAY NOT IN USE ANYMORE writeme = day+"-"+month+"-"+year;
_("getDateString__ returning "+writeme);
return writeme;
}
//takes a date object in and returns a string like 19/09/2011
public static String getDateString___(Date d)
{
Calendar calendar = null;
calendar = Calendar.getInstance();
calendar.setTime(d);
String day = calendar.get(Calendar.DAY_OF_MONTH)+"";
String month = (calendar.get(Calendar.MONTH)+1)+""; //month starts at 0 in java
if (month.length()==1)
{
month="0"+month; // getthe zero before or it looks odd
}
String year = calendar.get(Calendar.YEAR)+"";
return day+"/"+month+"/"+year;
}