Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- /*
- * File: main.cpp
- * Author: chrbro
- *
- * Created on 28 October 2016, 09:23
- */
- #include <cstdlib>
- #include <unicode/timezone.h>
- #include <unicode/unistr.h>
- #include <unicode/calendar.h>
- #include <unicode/datefmt.h>
- #include <unicode/ustdio.h>
- #include <iostream>
- #include <iomanip>
- #include <unicode/smpdtfmt.h>
- using namespace std;
- /*
- *
- */
- int main(int argc, char** argv) {
- UErrorCode success = U_ZERO_ERROR;
- UnicodeString dateReturned;
- int32_t stdOffset, dstOffset;
- //TimeZone *tzWest = TimeZone::createTimeZone("Australia/Adelaide");
- TimeZone *myzone = TimeZone::createTimeZone("Europe/London");
- //cout << myzone->getDSTSavings() << endl;
- UnicodeString dn;
- myzone->getDisplayName(false, myzone->SHORT, dn);
- u_printf("%S\n", dn.getTerminatedBuffer());
- time_t rawtime;
- struct tm * ptm, * ptm2;
- time(&rawtime);
- ptm = gmtime(&rawtime); // UTC
- UDate y = rawtime * 1e3; // milliseconds
- // Show timestamp
- UnicodeString fmt = "yyyy-MM-dd hh:mm:ss xxx zzz";
- SimpleDateFormat* formatter = new SimpleDateFormat (fmt, success);
- UnicodeString dateString;
- FieldPosition fp(FieldPosition::DONT_CARE);
- formatter->format(y, dateString, fp);
- u_printf("%S\n", dateString.getTerminatedBuffer());
- // Use getOffset to get the stdOffset and dstOffset for the given time
- myzone->getOffset(y, true, stdOffset, dstOffset, success);
- time_t mystdOffset = stdOffset / 1000;
- time_t mydstOffset = dstOffset / 1000;
- time_t newtime = rawtime - mydstOffset;
- cout << mystdOffset << endl;
- cout << mydstOffset << endl;
- ptm2 = localtime(&newtime);
- char buffer[80];
- strftime(buffer, 80, "%Y-%m-%d %H:%M:%S (%Z)", ptm2);
- cout << buffer << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement