2005年10月26日

public class Demo1 extends HttpServlet {
    private static final String CONTENT_TYPE = "text/html; charset=GBK";
    private static int idNum = 1;

    public void doGet(HttpServletRequest request, HttpServletResponse response) throws
            ServletException, IOException {
        response.setContentType(CONTENT_TYPE);
        PrintWriter out = response.getWriter();
        out.println("<html>");
        out.println("<head><title>Demo1</title></head>");

        synchronized(this){
            out.println("User-ID:" + idNum);
            idNum ++;
        }

        out.println("</body>");
        out.println("</html>");
        out.close();
    }

2005年10月23日

import java.text.SimpleDateFormat;
import java.util.Date;

public class DateExample2 {

    public static void main(String[] args) { //自己替换[]

        SimpleDateFormat bartDateFormat =
        new SimpleDateFormat("EEEE-MMMM-dd-yyyy");

        Date date = new Date();

        System.out.println(bartDateFormat.format(date));
    }
}

——————————————————————————-

import java.text.SimpleDateFormat;
import java.util.Date;

public class DateExample3 {

    public static void main(String[]args) { //自己替换[]
        // Create a date formatter that can parse dates of
        // the form MM-dd-yyyy.
        SimpleDateFormat bartDateFormat =
        new SimpleDateFormat("MM-dd-yyyy");

        // Create a string containing a text date to be parsed.
        String dateStringToParse = "9-29-2001";

        try {
            // Parse the text version of the date.
            // We have to perform the parse method in a
            // try-catch construct in case dateStringToParse
            // does not contain a date in the format we are expecting.
            Date date = bartDateFormat.parse(dateStringToParse);

            // Now send the parsed date as a long value
            // to the system output.
            System.out.println(date.getTime());
        }
        catch (Exception ex) {
            System.out.println(ex.getMessage());
        }
    }
}

—————————————————————————–

import java.text.DateFormat;
import java.util.Date;

public class DateExample4 {

    public static void main(String[] args) { //自己替换[]
        Date date = new Date();

        DateFormat shortDateFormat =
        DateFormat.getDateTimeInstance(
        DateFormat.SHORT,
        DateFormat.SHORT);

        DateFormat mediumDateFormat =
        DateFormat.getDateTimeInstance(
        DateFormat.MEDIUM,
        DateFormat.MEDIUM);

        DateFormat longDateFormat =
        DateFormat.getDateTimeInstance(
        DateFormat.LONG,
        DateFormat.LONG);

        DateFormat fullDateFormat =
        DateFormat.getDateTimeInstance(
        DateFormat.FULL,
        DateFormat.FULL);

        System.out.println(shortDateFormat.format(date));
        System.out.println(mediumDateFormat.format(date));
        System.out.println(longDateFormat.format(date));
        System.out.println(fullDateFormat.format(date));
    }
}