I have the following code in Java. I’ve been asked to port it to C++, however, I am not a Java developer. What would be the equivalent in C++:
public String formatDate( String string, Date time, TimeZone timeZone )
{
Calendar calendar = Calendar.getInstance( timeZone );
calendar.setTime( time );
StringBuffer answer = new StringBuffer();
SimpleDateFormat format = new SimpleDateFormat( string );
format.format( calendar, answer, null );
return answer.toString();
}
The following line is how it’s being called:
formatDate( "yyyy-MM-dd'T'HH:mm'Z'", new Date(), TimeZone.getTimeZone( "GMT" ));
The format string has ‘T’ and ‘Z’, which I cannot find much documentation on.
The T and Z are simply being inserted (note the quotes) and not being replaced as part of the formatting. Thus the above could give you
The Z would normally give you a time zone (e.g.
+0000) if it wasn’t quoted.