<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Flex Examples &#187; DateFormatter</title>
	<atom:link href="http://blog.flexexamples.com/category/dateformatter/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.flexexamples.com</link>
	<description>Just a bunch of Adobe Flex Examples</description>
	<lastBuildDate>Wed, 26 Jan 2011 18:09:51 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Scrubbing an FLV using the VideoDisplay control and a slider</title>
		<link>http://blog.flexexamples.com/2007/08/02/scrubbing-an-flv-using-the-videodisplay-control-and-a-slider/</link>
		<comments>http://blog.flexexamples.com/2007/08/02/scrubbing-an-flv-using-the-videodisplay-control-and-a-slider/#comments</comments>
		<pubDate>Thu, 02 Aug 2007 15:04:00 +0000</pubDate>
		<dc:creator>Peter deHaan</dc:creator>
				<category><![CDATA[DateFormatter]]></category>
		<category><![CDATA[VideoDisplay]]></category>
		<category><![CDATA[allowTrackClick]]></category>
		<category><![CDATA[invertThumbDirection]]></category>
		<category><![CDATA[playheadUpdate]]></category>

		<guid isPermaLink="false">http://blog.flexexamples.com/2007/08/02/scrubbing-an-flv-using-the-videodisplay-control-and-a-slider/</guid>
		<description><![CDATA[<p>In yet *another* post about the VideoDisplay control, this time we look at formatting playback times using the DateFormatter class/tag, creating a basic scrubber using an HSlider control, and applying a mildly annoying Zoom effect to the video.</p> <p>Also, we tweak the slider control (or more accurately HSlider) and prevent users from clicking on the [...]]]></description>
			<content:encoded><![CDATA[<p>In yet *another* post about the VideoDisplay control, this time we look at formatting playback times using the DateFormatter class/tag, creating a basic scrubber using an HSlider control, and applying a mildly annoying Zoom effect to the video.</p>
<p>Also, we tweak the slider control (or more accurately HSlider) and prevent users from clicking on the slider track (thanks to the <code>allowTrackClick</code> property, we set the <code>liveDragging</code> property to false to make sure we arent needlessly seeking around the video every time the slider thumb moves, and finally we invert the thumb arrow for no other reason than I didn&#8217;t know you could do that so easily.</p>
<p>Oh, and I also created a faux looping video by using the <code>autoRewind</code> property, and calling the <code>play()</code> method in the <code>rewind</code> event handler.</p>
<p>Full code after the jump.</p>
<p><span id="more-46"></span></p>
<p class="download"><a href="http://blog.flexexamples.com/wp-content/uploads/DateFormatter_format_test/main.mxml">View MXML</a></p>
<pre class="code">
&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" verticalAlign="top" backgroundColor="white"&gt;

    &lt;mx:Script&gt;
        &lt;![CDATA[
            private function formatTime(item:Date):String {
                return dateFormatter.format(item);
            }

            private function videoDisplay_playheadUpdate():void {
                /* If playhead time is 0, set to 100ms so the DateFormatter doesnt return an empty string. */
                var pT:Number = videoDisplay.playheadTime || 0.1;
                var tT:Number = videoDisplay.totalTime;

                /* Convert playheadTime and totalTime from seconds to milliseconds and create new Date objects. */
                var pTimeMS:Date = new Date(pT * 1000);
                var tTimeMS:Date = new Date(tT * 1000);

                timeLabel.text = formatTime(pTimeMS) + " / " + formatTime(tTimeMS);
            }

            private function slider_thumbPress():void {
                videoDisplay.pause();
            }

            private function slider_thumbRelease():void {
                videoDisplay.playheadTime = slider.value;
                videoDisplay.play();
            }

            private function videoDisplay_ready():void {
                videoDisplay.visible = true;
                controlBar.visible = true;
            }
        ]]&gt;
    &lt;/mx:Script&gt;

    &lt;!-- Only show minutes and seconds. --&gt;
    &lt;mx:DateFormatter id="dateFormatter" formatString="NN:SS" /&gt;

    &lt;mx:Zoom id="zoom" /&gt;

    &lt;mx:Panel title="{videoDisplay.source.split('/').pop()} ({videoDisplay.state})"&gt;
        &lt;mx:VideoDisplay id="videoDisplay" visible="false" showEffect="{zoom}"
            playheadUpdate="videoDisplay_playheadUpdate()"
            ready="videoDisplay_ready()"
            rewind="videoDisplay.play()"
            source="http://www.helpexamples.com/flash/video/cuepoints.flv" /&gt;

        &lt;mx:ControlBar id="controlBar" visible="false"&gt;
            &lt;mx:HSlider id="slider" width="100%"
                allowTrackClick="false"
                invertThumbDirection="true"
                liveDragging="false"
                maximum="{videoDisplay.totalTime}"
                minimum="0"
                thumbPress="slider_thumbPress()"
                thumbRelease="slider_thumbRelease()"
                tickInterval="1"
                value="{videoDisplay.playheadTime}" /&gt;
            &lt;mx:Label id="timeLabel" textAlign="right" /&gt;
        &lt;/mx:ControlBar&gt;
    &lt;/mx:Panel&gt;

&lt;/mx:Application&gt;
</pre>
<p class="information">View source enabled in the following example.</p>
<p><iframe src="http://blog.flexexamples.com/wp-content/uploads/DateFormatter_format_test/bin/main.html" width="100%" height="400"></iframe></p>
<div class="evernoteSiteMemory"><a href="javascript:" onclick="Evernote.doClip({title: 'Scrubbing an FLV using the VideoDisplay control and a slider on FlexExamples.com',url: 'http://blog.flexexamples.com/2007/08/02/scrubbing-an-flv-using-the-videodisplay-control-and-a-slider/',contentID: 'post-46',code: 'Pete9667',suggestNotebook: 'FlexExamples',suggestTags: 'allowTrackClick,invertThumbDirection,playheadUpdate',providerName: 'FlexExamples.com',styling: 'text' });return false" class="evernoteSiteMemoryLink"><img src="http://static.evernote.com/article-clipper-remember.png" class="evernoteSiteMemoryButton" />
				</a>				<div class="evernoteSiteMemoryClear">&nbsp;</div>
</div>]]></content:encoded>
			<wfw:commentRss>http://blog.flexexamples.com/2007/08/02/scrubbing-an-flv-using-the-videodisplay-control-and-a-slider/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>Calculating the number of days between two selected dates in a DateChooser control</title>
		<link>http://blog.flexexamples.com/2007/07/31/calculating-the-number-of-days-between-two-selected-dates-in-a-datechooser-control/</link>
		<comments>http://blog.flexexamples.com/2007/07/31/calculating-the-number-of-days-between-two-selected-dates-in-a-datechooser-control/#comments</comments>
		<pubDate>Wed, 01 Aug 2007 04:54:09 +0000</pubDate>
		<dc:creator>Peter deHaan</dc:creator>
				<category><![CDATA[Date]]></category>
		<category><![CDATA[DateChooser]]></category>
		<category><![CDATA[DateFormatter]]></category>
		<category><![CDATA[dataField]]></category>
		<category><![CDATA[rangeEnd]]></category>
		<category><![CDATA[rangeStart]]></category>
		<category><![CDATA[selectableRange]]></category>

		<guid isPermaLink="false">http://blog.flexexamples.com/2007/07/31/calculating-the-number-of-days-between-two-selected-dates-in-a-datechooser-control/</guid>
		<description><![CDATA[<p>Here&#8217;s a marginally more interesting sample. I was playing around with the DateChooser (calendar) control and the selectableRange property and figured I&#8217;d make a simple application to calculate the differences between two selected dates. The example creates a selectable range of dates from the current date to current date plus 1 year. Users can select [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a marginally more interesting sample. I was playing around with the DateChooser (calendar) control and the <code>selectableRange</code> property and figured I&#8217;d make a simple application to calculate the differences between two selected dates. The example creates a selectable range of dates from the current date to current date plus 1 year. Users can select any single or range of dates between the start date and end date, and Flex calculates the number of days the user selected using some basic math.</p>
<p><span id="more-43"></span></p>

<div class="wp_syntax"><div class="code"><pre class="mxml" style="font-family:monospace;"><span style="color: #000000;">&lt;?xml version=<span style="color: #ff0000;">&quot;1.0&quot;</span> encoding=<span style="color: #ff0000;">&quot;utf-8&quot;</span>?<span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Application</span> name=<span style="color: #ff0000;">&quot;DateChooser_selectableRange_test&quot;</span></span>
<span style="color: #000000;">        xmlns:mx=<span style="color: #ff0000;">&quot;http://www.adobe.com/2006/mxml&quot;</span></span>
<span style="color: #000000;">        layout=<span style="color: #ff0000;">&quot;vertical&quot;</span></span>
<span style="color: #000000;">        verticalAlign=<span style="color: #ff0000;">&quot;middle&quot;</span></span>
<span style="color: #000000;">        backgroundColor=<span style="color: #ff0000;">&quot;white&quot;</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
    <span style="color: #339933;">&lt;mx:Script&gt;</span>
<span style="color: #339933;">        &lt;![CDATA[</span>
<span style="color: #339933;">            import mx.controls.dataGridClasses.DataGridColumn;</span>
&nbsp;
<span style="color: #339933;">            /* Number of milliseconds in a day. (1000 milliseconds per second * 60 seconds per minute * 60 minutes per hour * 24 hours per day) */</span>
<span style="color: #339933;">            private const MS_PER_DAY:uint = 1000 * 60 * 60 * 24;</span>
&nbsp;
<span style="color: #339933;">            [Bindable]</span>
<span style="color: #339933;">            private var startDate:Date = new Date();</span>
&nbsp;
<span style="color: #339933;">            [Bindable]</span>
<span style="color: #339933;">            private var endDate:Date = new Date(startDate.fullYear + 1, startDate.month, startDate.date);</span>
&nbsp;
<span style="color: #339933;">            /* Default label function for the DataGrid. Basically just calls the DateFormatter on the current column's contents. */</span>
<span style="color: #339933;">            private function cellDateFormatter(item:Object, column:DataGridColumn):String {</span>
<span style="color: #339933;">                var columnDataField:String = column.dataField;</span>
<span style="color: #339933;">                return dateFormatter.format(item[columnDataField]);</span>
<span style="color: #339933;">            }</span>
&nbsp;
<span style="color: #339933;">            /* Custom label function for the last column. Calculates the number of days between the start date and end date. */</span>
<span style="color: #339933;">            private function calculateDays(item:Object, column:DataGridColumn):String {</span>
<span style="color: #339933;">                var tempDate:Date = new Date(item.rangeEnd - item.rangeStart);</span>
<span style="color: #339933;">                return Math.round((tempDate.time / MS_PER_DAY) + 1).toString();</span>
<span style="color: #339933;">            }</span>
<span style="color: #339933;">        ]]&gt;</span>
<span style="color: #339933;">    &lt;/mx:Script&gt;</span>
&nbsp;
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:DateFormatter</span> id=<span style="color: #ff0000;">&quot;dateFormatter&quot;</span> formatString=<span style="color: #ff0000;">&quot;MMM D, YYYY&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
&nbsp;
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:HBox</span><span style="color: #7400FF;">&gt;</span></span>
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:DateChooser</span> id=<span style="color: #ff0000;">&quot;dateChooser&quot;</span> selectableRange=<span style="color: #ff0000;">&quot;{{rangeStart:startDate, rangeEnd:endDate}}&quot;</span> allowMultipleSelection=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
&nbsp;
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:DataGrid</span> id=<span style="color: #ff0000;">&quot;selDates&quot;</span> dataProvider=<span style="color: #ff0000;">&quot;{dateChooser.selectedRanges}&quot;</span> labelFunction=<span style="color: #ff0000;">&quot;cellDateFormatter&quot;</span> verticalScrollPolicy=<span style="color: #ff0000;">&quot;on&quot;</span> height=<span style="color: #ff0000;">&quot;{dateChooser.height}&quot;</span><span style="color: #7400FF;">&gt;</span></span>
            <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:columns</span><span style="color: #7400FF;">&gt;</span></span>
                <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:DataGridColumn</span> dataField=<span style="color: #ff0000;">&quot;rangeStart&quot;</span> headerText=<span style="color: #ff0000;">&quot;Range Start:&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
                <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:DataGridColumn</span> dataField=<span style="color: #ff0000;">&quot;rangeEnd&quot;</span> headerText=<span style="color: #ff0000;">&quot;Range End:&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
                <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:DataGridColumn</span> labelFunction=<span style="color: #ff0000;">&quot;calculateDays&quot;</span> headerText=<span style="color: #ff0000;">&quot;Number Days:&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
            <span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:columns</span><span style="color: #7400FF;">&gt;</span></span>
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:DataGrid</span><span style="color: #7400FF;">&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:HBox</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:Application</span><span style="color: #7400FF;">&gt;</span></span></pre></div></div>

<div span="googleAdsLeaderboard">
<script type="text/javascript"><!--
google_ad_client = "pub-3325829455487492";
/* 728x90, created 7/15/09 */
google_ad_slot = "6403511741";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
<br />
</div>
<p class="information">View source enabled in the following example.</p>
<p><iframe src="http://blog.flexexamples.com/wp-content/uploads/DateChooser_selectableRange_test/bin/main.html" width="100%" height="250"></iframe></p>
<div class="evernoteSiteMemory"><a href="javascript:" onclick="Evernote.doClip({title: 'Calculating the number of days between two selected dates in a DateChooser control on FlexExamples.com',url: 'http://blog.flexexamples.com/2007/07/31/calculating-the-number-of-days-between-two-selected-dates-in-a-datechooser-control/',contentID: 'post-43',code: 'Pete9667',suggestNotebook: 'FlexExamples',suggestTags: 'dataField,rangeEnd,rangeStart,selectableRange',providerName: 'FlexExamples.com',styling: 'text' });return false" class="evernoteSiteMemoryLink"><img src="http://static.evernote.com/article-clipper-remember.png" class="evernoteSiteMemoryButton" />
				</a>				<div class="evernoteSiteMemoryClear">&nbsp;</div>
</div>]]></content:encoded>
			<wfw:commentRss>http://blog.flexexamples.com/2007/07/31/calculating-the-number-of-days-between-two-selected-dates-in-a-datechooser-control/feed/</wfw:commentRss>
		<slash:comments>26</slash:comments>
		</item>
		<item>
		<title>Formatting dates using the DateFormatter</title>
		<link>http://blog.flexexamples.com/2007/07/30/formatting-dates-using-the-dateformatter/</link>
		<comments>http://blog.flexexamples.com/2007/07/30/formatting-dates-using-the-dateformatter/#comments</comments>
		<pubDate>Tue, 31 Jul 2007 05:11:47 +0000</pubDate>
		<dc:creator>Peter deHaan</dc:creator>
				<category><![CDATA[DateField]]></category>
		<category><![CDATA[DateFormatter]]></category>
		<category><![CDATA[firstDayOfWeek]]></category>
		<category><![CDATA[labelFunction]]></category>

		<guid isPermaLink="false">http://blog.flexexamples.com/2007/07/30/formatting-dates-using-the-dateformatter/</guid>
		<description><![CDATA[<p>Another basic little example showing how to format the text in a DateField control using the DateFormatter and the DateField control&#8217;s labelFunction property. This entry also shows the pretty basic trick of creating a separate ActionScript class file that holds the day names as constants so you don&#8217;t constantly have to think whether Monday is [...]]]></description>
			<content:encoded><![CDATA[<p>Another basic little example showing how to format the text in a DateField control using the DateFormatter and the DateField control&#8217;s <code>labelFunction</code> property. This entry also shows the pretty basic trick of creating a separate ActionScript class file that holds the day names as constants so you don&#8217;t constantly have to think whether Monday is day 0 or day 1 (hint: it is day 1).</p>
<p>Full code after the jump.</p>
<p><span id="more-41"></span></p>
<p class="download"><a href="http://blog.flexexamples.com/wp-content/uploads/DateField_labelFunction_test/main.mxml">View MXML</a></p>
<pre class="code">
&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" verticalAlign="middle" backgroundColor="white"&gt;

    &lt;mx:Script&gt;
        &lt;![CDATA[
            private function doLabel(item:Date):String {
                return dateFormatter.format(item);
            }
        ]]&gt;
    &lt;/mx:Script&gt;

    &lt;mx:DateFormatter id="dateFormatter" formatString="MMM D, YYYY"/&gt;

    &lt;mx:DateField todayColor="red" labelFunction="doLabel" firstDayOfWeek="{Days.MONDAY}" /&gt;

&lt;/mx:Application&gt;
</pre>
<p class="information">Days.as</p>
<pre class="code">
// ActionScript file
package {
    public class Days {
        public static const SUNDAY:uint = 0;
        public static const MONDAY:uint = 1;
        public static const TUESDAY:uint = 2;
        public static const WEDNESDAY:uint = 3;
        public static const THURSDAY:uint = 4;
        public static const FRIDAY:uint = 5;
        public static const SATURDAY:uint = 6;
    }
}
</pre>
<p class="information">View source enabled in the following example</p>
<p><iframe src="http://blog.flexexamples.com/wp-content/uploads/DateField_labelFunction_test/bin/main.html" width="100%" height="300"></iframe></p>
<div class="evernoteSiteMemory"><a href="javascript:" onclick="Evernote.doClip({title: 'Formatting dates using the DateFormatter on FlexExamples.com',url: 'http://blog.flexexamples.com/2007/07/30/formatting-dates-using-the-dateformatter/',contentID: 'post-41',code: 'Pete9667',suggestNotebook: 'FlexExamples',suggestTags: 'firstDayOfWeek,labelFunction',providerName: 'FlexExamples.com',styling: 'text' });return false" class="evernoteSiteMemoryLink"><img src="http://static.evernote.com/article-clipper-remember.png" class="evernoteSiteMemoryButton" />
				</a>				<div class="evernoteSiteMemoryClear">&nbsp;</div>
</div>]]></content:encoded>
			<wfw:commentRss>http://blog.flexexamples.com/2007/07/30/formatting-dates-using-the-dateformatter/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

