Export (0) Print
Expand All

DateFormat.format Method (Date)

Visual Studio 2005

Formats a Date object into a string.

Package: java.text

Assembly: vjslib (in vjslib.dll)


public final java.lang.String format(
    java.util.Date date);

Parameters

date

The Date object to be formatted into a string.

A String object containing the formatted Date object.

The following example shows how to format a Date object.

// dateformat_format.jsl

import java.text.*;
import java.util.Date;

public class Program
{
    public static void main(String[] args)
    {
        // Apply a pattern to a SimpleDateFormat object.
        String pattern =
            "'This moment: 'dd MMM yyyy '@'hh 'hours and 'mm 'minutes.'";
        SimpleDateFormat sdf = new SimpleDateFormat(pattern);

        // Print out the time now using the format method.
        System.out.println(sdf.format(new Date()));
    }
}

/*
Sample Output:
This moment: 11 Nov 2004 @01 hours and 14 minutes.
*/

Community Additions

ADD
Show:
© 2014 Microsoft