PDA

View Full Version : How to get a vaild mail time GMT?



patrik08
28th May 2006, 11:15
How to get a vaild mail time +0200 GMT or so....
and not local LANG month day letter?

this return Date: lun, 28 feb 2006 11:06:17 +0200 italian LANG...



QString Smtp::TimeStampMail()
{
/* Date: Mon, 08 May 2006 17:57:52 +0200 */
/* Date: Sun, 28 May 2006 06:32:25 -0420 */
QDateTime dt = QDateTime::currentDateTime();
QDate timecute;
QString day_en = timecute.shortDayName(timecute.day());
QString month_en = timecute.shortMonthName (timecute.month());
QString last = dt.toString("yyyy hh:mm:ss");
QString maildate = QString( "Date: %1, %2 %3 %4 +0200" ).arg( day_en , QString::number(timecute.day()), month_en , last );
return maildate;
}

jacek
28th May 2006, 14:55
Please search the forum before you ask a question --- somebody had the same problem not so long ago. AFAIR you must switch locale to C or hardcode the month and day names.

patrik08
31st May 2006, 22:16
OK this work on different mail client ....
mail rtf Date format! http://www.faqs.org/rfcs/rfc788.html


insert foof day 0 zero/null


QStringList RTFdays = QStringList() << "foof" << "Mon" << "Tue" << "Wed" << "Thu" << "Fri" << "Sat" << "Sun";
QStringList RTFmonth = QStringList() << "foof" << "Feb" << "Mar" << "Apr" << "May" << "Jun" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec";








int dateswap(QString form, uint unixtime )
{
QDateTime fromunix;
fromunix.setTime_t(unixtime);
QString numeric = fromunix.toString((const QString)form);
bool ok;
return (int)numeric.toFloat(&ok);
}


QString TimeStampMail()
{
/* mail rtf Date format! http://www.faqs.org/rfcs/rfc788.html */
/* bybass qlocale Bug from window XP MUI */
uint unixtime = (uint)time( NULL );
QDateTime fromunix;
fromunix.setTime_t(unixtime);
QStringList RTFdays = QStringList() << "Mon" << "Tue" << "Wed" << "Thu" << "Fri" << "Sat" << "Sun";
QStringList RTFmonth = QStringList() << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec";
QDate timeroad(dateswap("yyyy",unixtime),dateswap("M",unixtime),dateswap("d",unixtime));
/*qDebug() << "### RTFdays " << RTFdays.at(timeroad.dayOfWeek());
qDebug() << "### RTFmonth " << RTFmonth.at(dateswap("M",unixtime));
qDebug() << "### yyyy " << dateswap("yyyy",unixtime);
qDebug() << "### M " << dateswap("M",unixtime);
qDebug() << "### d " << dateswap("d",unixtime);*/
QStringList rtfd_line;
rtfd_line.clear();
rtfd_line.append("Date: ");
rtfd_line.append(RTFdays.at(timeroad.dayOfWeek())) ;
rtfd_line.append(", ");
rtfd_line.append(QString::number(dateswap("d",unixtime)));
rtfd_line.append(" ");
rtfd_line.append(RTFmonth.at(dateswap("M",unixtime)));
rtfd_line.append(" ");
rtfd_line.append(QString::number(dateswap("yyyy",unixtime)));
rtfd_line.append(" ");
rtfd_line.append(fromunix.toString("hh:mm:ss"));
rtfd_line.append(" -0000");
/*qDebug() << "### mail rtf Date format " << rtfd_line.join("");*/
return QString(rtfd_line.join(""));

}