Posted By

chrisaiv on 04/07/11


Tagged

as3


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

sidneydekoning


AS3: Creating a Google Calendar RF3339 Timestamp


 / Published in: ActionScript 3
 

URL: http://snipplr.com/view/44492/javascript-create-rfc-3339-timestamps/

If you ever need to build a Flash mash-up on top of Google Calendar, you may need sync things through a timestamp. This example basically makes a request to my public Google calendar profile and says, "Give me any data based on what is happening right now". So the URL Request looks like this "http://www.google.com/calendar/feeds/MyCalendarFeed/public/basic?start-min=" + RF3339.timestamp();

  1. /*
  2.  * Timestampe to RF3339 Google Calendar Spec
  3.  *
  4. */
  5. package com.chrisaiv
  6. {
  7. public class RF3339
  8. {
  9. public function RF3339()
  10. {
  11. }
  12.  
  13. public static function timestamp(date=null):String
  14. {
  15. date = date ? date : new Date();
  16. var offset = date.getTimezoneOffset();
  17.  
  18. return pad(date.getFullYear(), 4 )
  19. + "-" + pad( date.getMonth() + 1, 2 )
  20. + "-" + pad( date.getDate(), 2 )
  21. + "T" + pad( date.getHours(), 2 )
  22. + ":" + pad( date.getMinutes(), 2 )
  23. + ":" + pad( date.getSeconds(), 2 )
  24. + "." + pad( date.getMilliseconds(), 3 )
  25. + ( offset > 0 ? "-" : "+" )
  26. + pad( Math.floor( Math.abs( offset ) / 60 ), 2 )
  27. + ":" + pad( Math.abs( offset ) % 60, 2 );
  28. }
  29.  
  30. public static function pad(amount, width)
  31. {
  32. var padding = "";
  33. while (padding.length < width - 1 && amount < Math.pow(10, width - padding.length - 1))
  34. {
  35. padding += "0";
  36. }
  37. return padding + amount.toString();
  38. }
  39. }
  40. }

Report this snippet  

You need to login to post a comment.