Return to Snippet

Revision: 44153
at April 7, 2011 03:37 by chrisaiv


Initial Code
/*
 * 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();
		}
	}
}

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

Initial Description
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();

Initial Title
AS3: Creating a Google Calendar RF3339 Timestamp

Initial Tags


Initial Language
ActionScript 3