Forum di AAC   |      Messaggi privati   |      English



ArcadiA Club
ArcadiA Club




Home Page   Home Page
programmazione.htm   Programmazione - FORUM sezione  Vai al FORUM
 
Username:
Password:
Iscriviti!  |  Recupero password



Iscriviti GRATIS, potrai navigare senza questa
fascia e accedere a contenuti esclusivi:

    E-Mail:

Password:



 

 
- La funzione FormatDateTime in JavaScript -
 
COSA SERVE PER QUESTO TUTORIAL
Download | Chiedi sul FORUM | Glossario Qualche conoscenza di base dell'HTML e di Javascript - Blocco Note o un qualsiasi editor di codice HTML.
Trasposizione della funzione FormatDateTime di VB in JavaScript

CODICE SORGENTE

<html>

<head>
<script type="text/javascript" language="javascript">

function FormatDateTime(DateTime, FormatType)
{
    var gg;
    var mm;
    
    if (DateTime == null)
        return (false);
    
    if (FormatType < 0)
        FormatType = 1;
    
    if (FormatType > 2)
        FormatType = 2;
    
    var strDate = new String(DateTime);
    
    if (strDate.toUpperCase() == "NOW")
    {
        var myDate = new Date();
        strDate = String(myDate);
    }
    else
    {
        var myDate = new Date(DateTime);
        strDate = String(myDate);
    }
    
    var Day = new String(strDate.substring(0, 3));
    if (Day == "Sun") Day = "Sunday";
    if (Day == "Mon") Day = "Monday";
    if (Day == "Tue") Day = "Tuesday";
    if (Day == "Wed") Day = "Wednesday";
    if (Day == "Thu") Day = "Thursday";
    if (Day == "Fri") Day = "Friday";
    if (Day == "Sat") Day = "Saturday"; 
    
    var Month = new String(strDate.substring(4, 7)), MonthNumber = 0;
    if (Month == "Jan") { Month = "January"; MonthNumber = "01"; }
    if (Month == "Feb") { Month = "February"; MonthNumber = "02"; }
    if (Month == "Mar") { Month = "March"; MonthNumber = "03"; }
    if (Month == "Apr") { Month = "April"; MonthNumber = "04"; }
    if (Month == "May") { Month = "May"; MonthNumber = "05"; }
    if (Month == "Jun") { Month = "June"; MonthNumber = "06"; }
    if (Month == "Jul") { Month = "July"; MonthNumber = "07"; }
    if (Month == "Aug") { Month = "August"; MonthNumber = "08"; }
    if (Month == "Sep") { Month = "September"; MonthNumber = "09"; }
    if (Month == "Oct") { Month = "October"; MonthNumber = "10"; }
    if (Month == "Nov") { Month = "November"; MonthNumber = "11"; }
    if (Month == "Dec") { Month = "December"; MonthNumber = "12"; }
    
    var curPos = 11;
    var MonthDay = new String(strDate.substring(8, 10));
    if (MonthDay.charAt(1) == " ")
    {
        MonthDay = "0" + MonthDay.charAt(0);
        curPos--;
    } 
    
    var Year = new String(strDate.substring(strDate.length - 4, strDate.length));
    
    // Format Type decision time!
    if (FormatType == 1)
        strDate = Day + ", " + Month + " " + MonthDay + ", " + Year;
    else if (FormatType == 2)
        strDate = MonthDay + "/" + MonthNumber + "/" + Year;
    
    return strDate;
}

</script>
</head>
<body>

<p>
<input type="text" name="txtDate" value="21-09-1979">
<select name="lstDateType">
<option value="0">vbGeneralDate</option>
<option value="1">vbLongDate</option>
<option value="2">vbShortDate</option>
</select>
<input type="button" value="FormatDateTime" 
 onclick="alert(FormatDateTime(txtDate.value, lstDateType.item(lstDateType.selectedIndex).value))">
</p>

</body>
</html>

<< INDIETRO by Vallerugo Luca  


Video collegati Visualizza i video di questa pagina
Visualizza video sull'argomento "script".
Visualizza video sull'argomento "funzione".
Visualizza video sull'argomento "format".
Visualizza video sull'argomento "date".
Visualizza video sull'argomento "time".
Visualizza video sull'argomento "javascript".
Visualizza video sull'argomento "script funzione format date time javascript".


Dì la tua: cosa ne pensi?
Esponi il tuo punto di vista e condividilo con migliaia di persone

Oggetto nuova discussione:


Testo del messaggio:

E-Mail:

Quanto fa più dieci:




Una discussione di questa sezione

vaglia postale

per quanto tempo devo conservare ricevuta vaglia postale

LEGGI TUTTA LA DISCUSSIONE


Risposta 1

Beh tu tienila sempre. L'hai persa?

LEGGI TUTTE LE RISPOSTE

 




^ TOP  
Linkaci | Segnala errore | Invita | Stampa


pubblicità | regole | visione | diritti | ufficio stampa | donazioni | scrivici
© 1999-2012 - P.IVA 02284690035 - Grafica, layout e contenuti sono di esclusiva proprietà di ArcadiA Club.

Powered by:
Spazi pubblicitari di alto livello
 

Compra in un click! | Cerca prodotti in offerta: