<%@ Page Language="VB" ResponseEncoding="iso-8859-1" Inherits="AACPage" %> <%@ import Namespace="System.Data" %> <%@ import Namespace="System.Data.Oledb" %> <%@ import Namespace="System.Data.ODBC" %> <%@ Register TagPrefix="aac" TagName="header" Src="~/header.ascx" %> <%@ Register TagPrefix="aac" TagName="footer" Src="~/footer.ascx" %> <%@ Register TagPrefix="aac" TagName="telaioHeader" Src="~/service/include/telaio_header.ascx" %> <%@ Register TagPrefix="aac" TagName="telaioFooter" Src="~/service/include/telaio_footer.ascx" %> <%@ Register TagPrefix="aac" TagName="autoreFile" Src="~/service/include/autore_file.ascx" %> <%@ Register TagPrefix="aac" TagName="aggiornamenti" Src="~/service/include/aggiornamenti.ascx" %> <%@ Register TagPrefix="aac" TagName="ultimiPost" Src="~/forum/inc_ultimi_post.ascx" %> <%@ Register TagPrefix="aac" TagName="ultimiPost3" Src="~/forum/inc_ultimi_post_nuovo.ascx" %> <%@ Register TagPrefix="aac" TagName="aspect" Src="~/service/include/aspect.ascx" %> <%@ Register TagPrefix="aac" TagName="adsenseGenerator" Src="~/service/include/adsense_generator.ascx" %> <% 'Il controllo per il paging correntemente registrato qua e l, ma andrebbe 'eliminato da tutte le parti e messo qui '<'%@ Register TagPrefix="aac" TagName="paging" Src="~/service/include/paging.ascx" %'> %> ArcadiA Club - JavaScript | La funzione FormatDateTime in JavaScript <% sez_id = 18 immm = "programmazione" categoria = 1 #CONST aspect_asp = 0 forum_id_asp = "16" sc_asp = 1 %> <%-- --%>
 
- 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