Lomadee, uma nova espécie na web. A maior plataforma de afiliados da América Latina



Luiz Henrique de Angeli

luizdeangeli@gmail.com


Somando e Subtraindo Datas

segunda-feira, 26 de outubro de 2009


Um simples exemplos para somar e subtrair Datas.

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"> 
 <mx:TitleWindow x="64" y="10" width="450" layout="horizontal" title="Somando Datas">
  <mx:DateField id="dtfData" formatString="DD/MM/YYYY"/>  
  <mx:Label text="+" fontWeight="bold" fontSize="12"/>
  <mx:NumericStepper id="nmsDias"/>  
  <mx:Label text="=" fontWeight="bold" fontSize="12"/>
  <mx:DateField formatString="DD/MM/YYYY" selectedDate="{somarData(dtfData.selectedDate,nmsDias.value)}"/>
 </mx:TitleWindow>
 <mx:TitleWindow x="64" y="118" width="450" layout="horizontal" title="Subtraindo Datas">
  <mx:DateField id="dtfInicial" formatString="DD/MM/YYYY"/>  
  <mx:Label text="-" fontWeight="bold" fontSize="12"/>
  <mx:DateField id="dtfFinal" formatString="DD/MM/YYYY"/>
  <mx:Label text="{subtrairData(dtfInicial.selectedDate,dtfFinal.selectedDate)}"/>   
 </mx:TitleWindow>
 
 <mx:DateFormatter id="dtfFormatada" formatString="DD/MM/YYYY"/>

 <mx:Script>
  <![CDATA[
   private function somarData(data : Date, dias : int):Date
   {
    return new Date(data.getTime() + (dias * 1000 * 60 * 60 * 24));
   }   

   private function subtrairData(dataInicial : Date, dataFinal : Date):int
   {   
    return Math.abs((dataFinal.getTime() - dataInicial.getTime()) / (1000 * 60 * 24 * 60));    
   }
  ]]>
 </mx:Script> 
</mx:Application>

0 comentários:


Submarino.com.br
Submarino.com.br