Java Tutorial/JSP/Data Type

Материал из Java эксперт
Перейти к: навигация, поиск

An Automatic Data Conversion

   <source lang="java">

<HTML>

 <HEAD>
   <TITLE>An Automatic Data Conversion</TITLE>
 </HEAD>
 <BODY>

An Automatic Data Conversion

   <%
       double double1;
       float float1 = 1;
       double1 = float1;
       out.println("double1 = " + float1);
    %>
 </BODY>

</HTML></source>





Casting to a New Type

   <source lang="java">

<HTML>

 <HEAD>
   <TITLE>Casting to a New Type</TITLE>
 </HEAD>
 <BODY>

Casting to a New Type

   <%
       float float1;
       double double1 = 1;
       float1 = (float) double1;
       out.println("float1 = " + float1);
    %>
 </BODY>

</HTML></source>





Date format

   <source lang="java">

<%--

 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 %></source>





Format Date

   <source lang="java">

<%--

 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 %>
<%

     Thread.sleep(250);
  }

%></source>