Advertisement
Guest User

Untitled

a guest
Oct 28th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6.  
  7. /*
  8. * File: main.cpp
  9. * Author: chrbro
  10. *
  11. * Created on 28 October 2016, 09:23
  12. */
  13.  
  14. #include <cstdlib>
  15. #include <unicode/timezone.h>
  16. #include <unicode/unistr.h>
  17. #include <unicode/calendar.h>
  18. #include <unicode/datefmt.h>
  19. #include <unicode/ustdio.h>
  20. #include <iostream>
  21. #include <iomanip>
  22. #include <unicode/smpdtfmt.h>
  23.  
  24. using namespace std;
  25.  
  26. /*
  27. *
  28. */
  29. int main(int argc, char** argv) {
  30. UErrorCode success = U_ZERO_ERROR;
  31. UnicodeString dateReturned;
  32. int32_t stdOffset, dstOffset;
  33.  
  34. //TimeZone *tzWest = TimeZone::createTimeZone("Australia/Adelaide");
  35. TimeZone *myzone = TimeZone::createTimeZone("Europe/London");
  36. //cout << myzone->getDSTSavings() << endl;
  37. UnicodeString dn;
  38. myzone->getDisplayName(false, myzone->SHORT, dn);
  39. u_printf("%S\n", dn.getTerminatedBuffer());
  40.  
  41. time_t rawtime;
  42. struct tm * ptm, * ptm2;
  43. time(&rawtime);
  44. ptm = gmtime(&rawtime); // UTC
  45.  
  46. UDate y = rawtime * 1e3; // milliseconds
  47.  
  48. // Show timestamp
  49. UnicodeString fmt = "yyyy-MM-dd hh:mm:ss xxx zzz";
  50. SimpleDateFormat* formatter = new SimpleDateFormat (fmt, success);
  51. UnicodeString dateString;
  52. FieldPosition fp(FieldPosition::DONT_CARE);
  53. formatter->format(y, dateString, fp);
  54. u_printf("%S\n", dateString.getTerminatedBuffer());
  55.  
  56. // Use getOffset to get the stdOffset and dstOffset for the given time
  57. myzone->getOffset(y, true, stdOffset, dstOffset, success);
  58. time_t mystdOffset = stdOffset / 1000;
  59. time_t mydstOffset = dstOffset / 1000;
  60. time_t newtime = rawtime - mydstOffset;
  61. cout << mystdOffset << endl;
  62. cout << mydstOffset << endl;
  63.  
  64. ptm2 = localtime(&newtime);
  65. char buffer[80];
  66. strftime(buffer, 80, "%Y-%m-%d %H:%M:%S (%Z)", ptm2);
  67. cout << buffer << endl;
  68.  
  69.  
  70.  
  71.  
  72. return 0;
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement