Programming Tutorials Browser Tutorials Articles Struts Tutorials Hibernate Tutorials

Search: 

  Tutorial: ASP.NET .NET Formatting Numbers, Dates, and Times in ASP.NET Tutorial

One of the nice things about VBScript was its built-in formatting functions, such as FormatCurrency, FormatNumber, FormatDateTime, etc. Read on to learn how to use these functions.

Tutorial Details:

ASP FAQS : ASP.NET

Question : How can I format numbers and date/times using ASP.NET? For example, I want to format a number as a currency.

Answer : One of the nice things about VBScript was its built-in formatting functions, such as FormatCurrency , FormatNumber , FormatDateTime , etc. (For more information on these functions see this FAQ or, better yet, check out the Strings FAQ Category .)

When creating ASP.NET Web pages with VB.NET, you can still use these functions, although you will need to import the Microsoft.VisualBasic namespace. But what if you are using C#, or want to start using the new formatting methods available in .NET? To allow for formatting, the .NET Framework contains a general String.Format static method along with .ToString() methods for each object.
So, first off, you can easily convert a non-string data type to a string by using it's .ToString method. That is, if you wanted to turn a DateTime variable into a string you could do:

'Create a var. named rightNow and set it to the current date/time
Dim rightNow as DateTime = DateTime.Now
Dim s as String 'create a string
s = rightNow.ToString()
This simple code snippet creates a DateTime variable ( rightNow ) that is assigned the current system date/time. A String variable ( s ) is then created and assigned the string representation of the DateTime variable.
The .ToString() contains an overloaded variant that accepts a single String parameter. This parameter can be used to specify how to format the DateTime variable. For example, if we wanted to display the date as a three-lettered month namethen the day, and then a comma followed by the year in four digits (like Jan 30, 2002), we could use the .ToString( formatString ) method like so:
'Create a var. named rightNow and set it to the current date/time
Dim rightNow as DateTime = DateTime.Now
Dim s as String 'create a string
s = rightNow.ToString("MMM dd, yyyy")
Pretty neat, eh? Of course the question still remains: "How in the world did I know to use MMM to display the three-letter abbreviation of a month? The answer, of course, is to hit the documentation. One thing the .NET Framework has an abundance of is documentation. For a list of special formatting characters for date/time purposes, see DateTimeFormatInfo Class .


 

Read Tutorial at: Click here to view the tutorial

Rate Tutorial:
ASP.NET .NET Formatting Numbers, Dates, and Times in ASP.NET Tutorial

View Tutorial:
ASP.NET .NET Formatting Numbers, Dates, and Times in ASP.NET Tutorial

Related Tutorials:

Displaying 1 - 50 of about 2053 Related Tutorials.

ASP.NET Web Hosting
for the development of web applications. ASP.NET is built upon the .NET Framework... ASP.Net Web Hosting,ASP.Net Hosting,ASP Web Hosting Services,ASP Hosting ASP.NET Web Hosting  
 
ASP.NET books
ASP.NET books ASP.NET books  ... ASP.Net provides the most powerful environment for development..., to satiate our technical appetite. Page-2 ASP.NET is a web programming platform
 
ASP.NET books
ASP.NET books ASP.NET books  ... ASP.Net provides the most powerful environment for development..., to satiate our technical appetite. Page-2 ASP.NET is a web programming platform
 
ASP.NET books Page2
ASP.NET books Page2 ASP.NET books Page2...; Introduction of ASP.NET ASP.NET is a web programming platform developed... with the .NET versions. This wikibook is an introduction to ASP.NET. It assumes
 
ASP.NET books Page1
;         Tutorial of ASP.NET 2.0...;       The ASP.NET QuickStart Tutorial... ASP.NET books Page1 ASP.NET books Page1
 
SQL Between Timestamp
; A timestamp is used to catch the dates and times.  Understand with Example The Tutorial illustrate an example to create a SQL
 
Various time classes
times and dates. java.util.Date - A common representation of dates.... java.text.SimpleDateFormat - Useful for both parsing and formatting dates... to get the current date and time, represent dates and times for the past
 
Open Source Intranet
Open Source Intranet Open Source Intranet Digger Solutions-Intranet Open Source Digger Solutions Nos.NET is an ASP.NET e... that you have loved, but better! Along with the upgrade to ASP.NET we also
 
Formatting Date for a Locale Example
class use for formatting and parsing dates. It allows for formatting date... Formatting Date for a Locale Example Formatting Date for a Locale Example      
 
Beginners Java Tutorial
java Beginner,java Beginners,Beginning java,Beginners Java Tutorial,Java for beginners Beginners Java Tutorial...; This tutorial will introduce you with the Java Programming
 
Current Running Projects on roseindia.net
system SS7 real message communication tutorial design using ASP.NET - Call Flow 1
 
Converting Numbers to Strings
() for this. This program uses the same formatting object many times. 1 2 3 4 5... Java: Converting Numbers to Strings Java: Converting Numbers to Strings Vanilla Java: Converting
 
Beginners Java Tutorial
java Beginner,java Beginners,Beginning java,Beginners Java Tutorial,Java for beginners Beginners Java Tutorial...; This tutorial will introduce you with the Java Programming
 
Mysql Date
retrieve the date with the help of timestamp. Timestamp is used to catch all dates and times. Understand with Example The Tutorial explains you 'Mysql Date
 
Wicket on Net Beans IDE
Wicket on Net Beans IDE Wicket on Net Beans IDE...;   This tutorial will take you through the basics of creating... the step by step procedure to run Wicket on Net Beans IDE. First of all you must have
 
Calculate the Sum of three Numbers
Sum of Three Numbers,Calculating Sum of 3 Numbers,Java Addition of Three Numbers Example Calculate the Sum of Three Numbers...;   This is simple java programming tutorial . In this section you
 
JavaScript array of numbers
JavaScript array of numbers JavaScript array of numbers          ...;    In this tutorial we want to describe you a code
 
Swapping of two numbers
Java Swapping,Java Swapping Integer,Swapping of Two Numbers in Java Swapping of two numbers    ... tutorial will teach you the methods for writing program to calculate swap of two
 
Spyware - The Internet Devil Of Our Times!
times, so that people can enjoy surfing the net, without compromising privacy... Spyware - The Internet Devil Of Our Times! Spyware - The Internet Devil Of Our Times
 
Get Time And Date
; dates as year, month, day, hour, minute, and second values and date formatting and parsing of date string. Understand with Example In this Tutorial we want... millisecond. 2)SimpleDateFormat- is a  formatting concrete class
 
JSF Tutorial for Beginners
to develop ASP.net web forms.(please refer to a tutorial on ASP.net in ... JSF TUTORIAL - INTRODUCING   JAVA  SERVER  FACES... the transition phase.   In this three  part  tutorial
 
Numbers
Java: Numbers Java NotesNumbers Two kinds of numbers. There are basically two kinds of numbers... the type int) and binary floating-point numbers (most commonly using the type
 
J2EE Tutorial - Session Tracking Example
J2EE Tutorial - Session Tracking Example J2EE Tutorial - Session Tracking Example     ... for all platforms. Hence the superiority of ASP.net webservice over DCOM
 
Swap two any numbers
Swap Any Two Numbers,Swapping Numbers in Java,How to Swap Numbers,Swaping Numbers Example in Java Swap Any Two Numbers... are newbie in Java programming then our tutorial and example are helpful
 
Beginners Stuts tutorial.
Architects in Enterprise level, favour the Struts Framework .In this  tutorial... of Struts Tutorial ,  Ted Husted, had to admit that the Struts naming... in ASP.net and JSF).   iii) thousands of concurrent users   iv) huge
 
Dot Net Architect
Dot Net Architect Dot Net Architect...; Position Vacant: Dot Net Architect Job Description  Candidates will be handling Dot Net Projects.   
 
WEBSERVICE USING APACHE AXIS TUTORIAL-1
(jws)? from Tomcat/Axis and consuming that service in an ASP.net program.This...,while the other aim is tackling the firewall problem. (Since ASP.net runs only... that DotNet SDK has already been installed and tested,for running asp.net programs. ?? 1
 
Number Format Example
;   This Example shows you how to format numbers according to the locale. In the code given below we are formatting number according... : NumberFormat.getNumberInstance() : NumberFormat class provides the functionality for formatting and parsing
 
Comparing Dates in Java
Comparing Dates in Java,How to Compare Two Dates,Compare Date With Current Date Example Comparing Dates in Java...; This example illustrates you how to compare two dates. Generally dates
 
J2EE Tutorial - Introduction
J2EE Tutorial - Introduction J2EE Tutorial... want to know whether J2EE is Java atall or something else. This tutorial... long journey and this 'short' tutorial cannot cover   all
 
Net caboodle plugin
Net caboodle plugin Net caboodle plugin...;  The Business 2 Mobile plugin from Net Caboodle makes it easy... the type of MIDP applications you can create with Net Caboodle, have some fun
 
Random numbers - Introduction
Java: Random numbers - Introduction Java NotesRandom numbers - Introduction When to use random numbers There are many types of programs that use random numbers. Game programs use
 
Comparing two Dates in Java
Comparing two Dates in Java, Dates in Java Comparing two Dates in Java       ... to compare two date objects using java.util.Date class. For comparing dates, we
 
Comparing the File Dates
Date Comparison in Java, Java Comparing Strings, File Date Comparison Comparing the File Dates    ... will help you to compare the dates of files. In java we have the option
 
Swap two any numbers (from Keyboard)
Java Swap,Swap in Java,Java Swap Integer,How to Swap Two Any Number Swap two any numbers (from Keyboard)  ... programming then our tutorial and example are helpful for understanding Java
 
Web Hosting Glossary
hosting resource on the net. RoseIndia.net web hosting resource offers hundreds... :: ColdFusion Web Hosting :: ASP.NET Web Hosting :: Front
 
Web Hosting
hosting resource on the net. RoseIndia.net web hosting resource offers hundreds... :: ColdFusion Web Hosting :: ASP.NET Web Hosting :: Front
 
OOP Tutorial [first draft]
Java: OOP Tutorial Java: OOP Tutorial [first draft] Table of contents Introduction... for a student. Follow the tutorial and you'll see how this can be improved
 
Comparing two Dates in Java with the use of before method
Comparing two Dates in Java with the use of before method, before method in java, before method Comparing two Dates in Java... of comparing dates you have seen how to use after() method in java class for comparing
 
JavaScript pow() method
;  Some times programmers may need to evaluate the value by the power of some numbers therefore JavaScript provides an in-built function Math.pow...; </center> </body> </html> Output : Input numbers
 
Mysql Date Format
; Mysql Date Format explains you the way of formatting Date. Understand with Example The Tutorial elaborate an example from 'Mysql Date Format'. To understand this example we show you the following Syntax used for formatting the date
 
Random Numbers - shuffling
Java: Random Numbers - shuffling Java NotesRandom Numbers - shuffling A standard approach..., which is described at the bottom. Shuffling: Random numbers without
 
Example program to change Date formatting Symbols
Example program to change Date formatting Symbols, change Date formatting Symbols, Date formatting Example program to change Date formatting Symbols       
 
Java get number of days between dates
Java get number of days between dates Java get number of days between dates      ... how to obtain the number of days between the two described dates. In order to get
 
Add two big numbers
Add Numbers Program,Add Two Big Numbers,Add Big Numbers In Java,Numbers Addition Code Java Add two big numbers...; In this section, you will learn how to add two big numbers. For adding two
 
Write a program to list all even numbers between two numbers
Java Even Numbers, List Even Numbers in Java Write a program to list all even numbers between two numbers  ... Even Numbers - Even Numbers Example in Java: Here you will learn to write a program
 
Random in jsp
; Random numbers are the numbers that are determined entirely by chance. User does not have any control over the working of random numbers. random... than 1.0. The random number are generated automatically. In this tutorial we
 
Comparing Two Numbers
Comparison in Java, Java Compare Numbers, Comparing Two Numbers in Java Comparing Two Numbers    ... simple example of Java that teaches you the method of comparing two numbers
 
GUI Tutorial I - FIRST DRAFT
Vanilla Java: GUI Tutorial First Draft Table of Contents GUI Tutorial I - FIRST DRAFT Table... after reading this tutorial. The tutorial presents model programs of increasing
 
Struts 2 Tutorial
Programming Tutorials Struts 2 Tutorial  ... Struts 2 Tutorial and Online free training helps you learn new elegant Struts 2... In this section you will learn how to format Date and numbers in Struts 2 Framework
 
Site navigation
 

 

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2006. All rights reserved.