How to parse date/time from string?

Although I don’t know how to format a single-digit month input in boost, I can do it after the two-digit edit: #include <iostream> #include <boost/date_time.hpp> namespace bt = boost::posix_time; const std::locale formats[] = { std::locale(std::locale::classic(),new bt::time_input_facet(“%Y-%m-%d %H:%M:%S”)), std::locale(std::locale::classic(),new bt::time_input_facet(“%Y/%m/%d %H:%M:%S”)), std::locale(std::locale::classic(),new bt::time_input_facet(“%d.%m.%Y %H:%M:%S”)), std::locale(std::locale::classic(),new bt::time_input_facet(“%Y-%m-%d”))}; const size_t formats_n = sizeof(formats)/sizeof(formats[0]); std::time_t pt_to_time_t(const bt::ptime& pt) { … Read more

Java Convert GMT/UTC to Local time doesn’t work as expected

I also recommend using Joda as mentioned before. Solving your problem using standard Java Date objects only can be done as follows: // **** YOUR CODE **** BEGIN **** long ts = System.currentTimeMillis(); Date localTime = new Date(ts); String format = “yyyy/MM/dd HH:mm:ss”; SimpleDateFormat sdf = new SimpleDateFormat(format); // Convert Local Time to UTC (Works … Read more

Generating a drop down list of timezones with PHP

I would do it in PHP, except I would avoid doing preg_match 100 some times and do this to generate your list. $tzlist = DateTimeZone::listIdentifiers(DateTimeZone::ALL); Also, I would use PHP’s names for the ‘timezones’ and forget about GMT offsets, which will change based on DST. Code like that in phpbb is only that way b/c … Read more