Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 22-12-2008
Member
 
Join Date: May 2008
Posts: 29
Formatting Dates

This sample shows the different ways we can format dates, using ASP.Net. Just pick a format type from the listbox, and the details about that particular formatting will appear on the right.


Code:
<%@ Page Language="VB" %>

<script language="VB" Runat="server">

Dim myDate as DateTime

Sub Page_Load(Source as Object, E as EventArgs)

myDate=DateTime.Now

if not Page.IsPostBack then

            lbDate.Items.Add(New ListItem("Short Date Format", "d"))

            lbDate.Items.Add(New ListItem("Long Date Format", "D"))

            lbDate.Items.Add(New ListItem("Short Time Format", "t"))

            lbDate.Items.Add(New ListItem("Long Time Format", "T"))

            lbDate.Items.Add(New ListItem("Full Date/Time Format (Short time)", "f"))

            lbDate.Items.Add(New ListItem("Full Date/Time Format (Long time)", "F"))

            lbDate.Items.Add(New ListItem("General Date/Time Format (Short time)", "g"))

            lbDate.Items.Add(New ListItem("General Date/Time Format (Long time)", "G"))

            lbDate.Items.Add(New ListItem("Month day format", "m"))

            lbDate.Items.Add(New ListItem("RFC 1123 format", "r"))

            lbDate.Items.Add(New ListItem("Sortable date/time format", "s"))

            lbDate.Items.Add(New ListItem("Universable sortable date/time format (short)", "u"))

            lbDate.Items.Add(New ListItem("Universable sortable date/time format (long)", "U"))

            lbDate.Items.Add(New ListItem("Year Month", "Y"))

end if

End Sub

 

Sub doDate(Source as Object, E as EventArgs)

if lbDate.SelectedItem.Value <>"None" then

            lblPattern.Text=lbDate.SelectedItem.Value

            lblType.text=lbDate.SelectedItem.Text

            lblOutput.text="String.Format(""{0:" & lbDate.SelectedItem.Value & "}"", Item)"

            lblExample.text=String.Format("{0:" & lbDate.SelectedItem.Value & "}", myDate)

End If

End Sub

 

</script>

<html>

<head>

            <meta name="GENERATOR" Content="ASP Express 3.1">

            <title>Formatting Dates</title>

</head>

<body>

<form id="form1" Runat="server">

<table>           

            <tr>

                        <td align="Left" valign="Top" Rowspan="5">

                                    <i><font Color="#FF0000"><b>Select Formatting Type:</b></font></i><br>

                                    <asp:ListBox id="lbDate"

                                                AutoPostBack="True"

                                                OnSelectedIndexChanged="doDate"

                                                Runat="server"/></td>

            </tr>

            <tr>

                        <td align="Right" valign="Top"><b>Format Pattern:</b> </td>

                        <td align="Left" valign="Top"><asp:Label ID="lblPattern" Runat="server" /></td>

            </tr>

            <tr>

                        <td align="Right" valign="Top"><b>Format Type:</b></td>

                        <td align="Left" valign="Top"><asp:Label ID="lblType" Runat="server" /></td>

            </tr>

            <tr>

                        <td align="Right" valign="Top"><b>Output: </b></td>

                        <td align="Left" valign="Top"><asp:Label ID="lblOutput" Runat="server" /></td>

            </tr>

            <tr>

                        <td align="Right" valign="Top"><b>Example: </b></td>

                        <td align="Left" valign="Top"><asp:Label ID="lblExample" Runat="server" />

                        </td>   

            </tr>

</table>

</form>

</body>

</html>
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Formatting Dates"
Thread Thread Starter Forum Replies Last Post
Formatting MS Excel 2010 vs. Formatting MS Excel 2003 Dalajit Windows Software 6 12-08-2011 10:19 PM
How to use Dates and Times in XForms? Zavier Software Development 5 03-03-2010 06:00 AM
Manipulation between two dates Ash maker Software Development 5 16-02-2010 02:31 AM
Default dates ssjones Hardware Peripherals 4 26-01-2009 10:50 PM


All times are GMT +5.5. The time now is 05:20 AM.