Java Tutorial/JSP/Data Type

Материал из Java эксперт
Версия от 17:44, 31 мая 2010; (обсуждение)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

An Automatic Data Conversion

<HTML>
  <HEAD>
    <TITLE>An Automatic Data Conversion</TITLE>
  </HEAD>
  <BODY>
    <H1>An Automatic Data Conversion</H1>
    <%
        double double1;
        float float1 = 1;
        double1 = float1;
        out.println("double1 = " + float1);
     %>
  </BODY>
</HTML>





Casting to a New Type

<HTML>
  <HEAD>
    <TITLE>Casting to a New Type</TITLE>
  </HEAD>
  <BODY>
    <H1>Casting to a New Type</H1>
    <%
        float float1;
        double double1 = 1;
        float1 = (float) double1;
        out.println("float1 = " + float1);
     %>
  </BODY>
</HTML>





Date format

<%--
  Copyright (c) 2002 by Phil Hanna
  All rights reserved.
  
  You may study, use, modify, and distribute this
  software for any purpose provided that this
  copyright notice appears in all copies.
  
  This software is provided without warranty
  either expressed or implied.
--%>
<%@ page import="java.text.*,java.util.*" session="false"%>
<%!
   DateFormat fmt = new SimpleDateFormat("hh:mm:ss aa");
   String now = fmt.format(new Date());
%>
The time is <%= now %>





Format Date

<%--
  Copyright (c) 2002 by Phil Hanna
  All rights reserved.
  
  You may study, use, modify, and distribute this
  software for any purpose provided that this
  copyright notice appears in all copies.
  
  This software is provided without warranty
  either expressed or implied.
--%>
<%@ page import="java.text.*" %>
<%@ page import="java.util.*" %>
<%! int count; %>
<%
   String requestTime =
      new SimpleDateFormat("hh:mm:ss a").format(new Date());
   count = 0;
   for (int i = 0; i < 10; i++) {
%>
Request at <%= requestTime %> count = <%= ++count %><br>
<%
      Thread.sleep(250);
   }
%>