/ Published in: ActionScript 3
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();
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
/* * Timestampe to RF3339 Google Calendar Spec * */ package com.chrisaiv { public class RF3339 { public function RF3339() { } public static function timestamp(date=null):String { date = date ? date : new Date(); var offset = date.getTimezoneOffset(); return pad(date.getFullYear(), 4 ) + "-" + pad( date.getMonth() + 1, 2 ) + "-" + pad( date.getDate(), 2 ) + "T" + pad( date.getHours(), 2 ) + ":" + pad( date.getMinutes(), 2 ) + ":" + pad( date.getSeconds(), 2 ) + "." + pad( date.getMilliseconds(), 3 ) + ( offset > 0 ? "-" : "+" ) + pad( Math.floor( Math.abs( offset ) / 60 ), 2 ) + ":" + pad( Math.abs( offset ) % 60, 2 ); } public static function pad(amount, width) { var padding = ""; while (padding.length < width - 1 && amount < Math.pow(10, width - padding.length - 1)) { padding += "0"; } return padding + amount.toString(); } } }
URL: http://snipplr.com/view/44492/javascript-create-rfc-3339-timestamps/