Originally Posted by
Salem
It's not two spaces after the month, it's the single digit day printed with a leading space.
What code are you using?
Ahh..ok. But why does it put a leading space before the day?
Here's my code (please ignore the debugging statements, most of which are commented out):
Code:
const char* properlyFormatDateAndTime(char* c_time) {
const char* properly_formatted_c_time;
string c_time_str = c_time;
cout<< "c_time is: ' " << c_time <<endl;
cin.get();
cout<< "c_time_str is: " << c_time_str <<endl;
cin.get();
string day_of_the_week = c_time_str.substr(0, c_time_str.find(' ', 0));
//cout<< "day_of_the_week is: " << day_of_the_week <<endl;
//cin.get();
c_time_str = c_time_str.substr(c_time_str.find(' ', 0) + 1);
//cout<< "c_time_str is: " << c_time_str <<endl;
//cin.get();
string month = c_time_str.substr(0, c_time_str.find(' ', 0));
//cout<< "month is: " << month <<endl;
//cin.get();
c_time_str = c_time_str.substr(c_time_str.find(' ', 0) + 1);
//cout<< "c_time_str is: " << c_time_str <<endl;
//cin.get();
string date = c_time_str.substr(0, c_time_str.find(' ', 0));
//cout<< "date is: " << date <<endl;
//cin.get();
c_time_str = c_time_str.substr(c_time_str.find(' ', 0) + 1);
//cout<< "c_time_str is: " << c_time_str <<endl;
//cin.get();
string current_time = c_time_str.substr(0, c_time_str.find(' ', 0) + 1);
//cout<< "current_time is: " << current_time <<endl;
//cin.get();
string hour = current_time.substr(0, current_time.find(':', 0));
if (hour.at(0) == '0') {
hour.erase(0, 1);
}
stringstream hour_ss;
hour_ss<< hour;
int hour_int;
hour_ss>> hour_int;
//cout<< "hour_int is: " << hour_int <<endl;
//cin.get();
string ampm = "AM";
if (hour_int > 12) {
ampm = "PM";
if (hour_int == 13)
hour_int = 1;
else if (hour_int == 14)
hour_int = 2;
else if (hour_int == 15)
hour_int = 3;
else if (hour_int == 16)
hour_int = 4;
else if (hour_int == 17)
hour_int = 5;
else if (hour_int == 18)
hour_int = 6;
else if (hour_int == 19)
hour_int = 7;
else if (hour_int == 20)
hour_int = 8;
else if (hour_int == 21)
hour_int = 9;
else if (hour_int == 22)
hour_int = 10;
else if (hour_int == 23)
hour_int = 11;
else if (hour_int == 24) {
hour_int = 12;
ampm = "AM";
}
}
//cout<< "hour_int is: " << hour_int <<endl;
//cin.get();
hour_ss.str("");
hour_ss.clear();
hour_ss<< hour_int;
hour = hour_ss.str();
//cout<< "hour is: " << hour <<endl;
//cin.get();
current_time = current_time.substr(current_time.find(':', 0) + 1);
string minutes = current_time.substr(0, current_time.find(':', 0));
//cout<< "minutes is: " << minutes <<endl;
//cin.get();
current_time = current_time.substr(current_time.find(':', 0) + 1);
string seconds = current_time.substr(0, current_time.find(' ', 0));
//cout<< "seconds is: " << seconds <<endl;
//cin.get();
string complete_time = hour + ":" + minutes + ":" + seconds + " " + ampm;
//cout<< "complete_time is: " << complete_time <<endl;
//cin.get();
c_time_str = c_time_str.substr(c_time_str.find(' ', 0) + 1);
//cout<< "c_time_str is: " << c_time_str <<endl;
//cin.get();
string year = c_time_str.substr(0, c_time_str.find('\n', 0));
/*
if (year.at(year.size() - 1) == '\n') {
cout<< "year is followed by a new line." <<endl;
cin.get();
}
*/
//cout<< "year is: " << year <<endl;
//cin.get();
string properly_formatted_c_time_str = complete_time + " - " + day_of_the_week + " " + month + " " + date + ", " + year;
//cout<< "properly_formatted_c_time_str is: " << properly_formatted_c_time_str <<endl;
//cin.get();
properly_formatted_c_time = properly_formatted_c_time_str.c_str();
//cout<< "properly_formatted_c_time is: " << properly_formatted_c_time <<endl;
//cin.get();
return properly_formatted_c_time;
}