java.util.Date date = new java.util.Date();
java.text.SimpleDateFormat sf = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String formateDate = sf.format(date);

解决方案 »

  1.   

    <%@ page import="java.util.Date"%>
    <%@ page import="java.text.SimpleDateFormat"%>
     Date serverTime = new Date(); 
     
     SimpleDateFormat smpDateFormat = new SimpleDateFormat("yyyy-MM-dd"); 
     String currDateTime = smpDateFormat.format(serverTime);
    文本诓.value=currDateTime 
      

  2.   

    显示:
    <input maxlength=110 name=shijian value="<%=formateDate%>">
      

  3.   

    来晚了。轮不到了。来点特殊的吧:
    <%@ page language="java" import="java.sql.*" import="java.io.*"%>
    <%@ page contentType="text/html;charset=gb2312"%>
    <%@ page import="java.util.*" import="java.text.*"%>
    <%
      String weekStr=null;//定义一个字符串型的星期变量
       GregorianCalendar gCalendar=new GregorianCalendar();//罗马日期类型,很有用
        int week=gCalendar.get(gCalendar.DAY_OF_WEEK);//得到星期的int值   java.util.Date currday=new java.util.Date();
       java.text.SimpleDateFormat dateformat=new java.text.SimpleDateFormat("yyyy-MM-dd ");
       //java.text.SimpleDateFormat date=new java.text.SimpleDateFormat("yyyy/MM/dd");
        int hour=currday.getHours();
        int min=currday.getMinutes();
        int sec=currday.getSeconds();
        
        String timeStr=""+hour+":"+min+":"+sec+"";
        switch(week)                //转换成字符串的星期表示
       {
          case 1:weekStr="星期日";
                 break;
          case 2:weekStr="星期一";
                 break;
          case 3:weekStr="星期二";
                 break;
          case 4:weekStr="星期三";
                 break;
          case 5:weekStr="星期四";
                 break;
          case 6:weekStr="星期五";
                 break;
          case 7:weekStr="星期六";
                 break;
       }
             
    %>
    日期:
    <%=dateformat.format(currday)%>
    星期:<%=weekStr%>
    时间:<%=timeStr%>
      

  4.   

    import java.awt.*;
    import javax.swing.*;
    import java.util.*;
    import java.text.*;public class showTime extends JFrame{
        JTextField tfTime;
        public showTime(){
            init();
        }
        public void init(){
    tfTime = new JTextField();
    Date date = new Date();
    SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    String formateDate = sf.format(date);
    tfTime.setText(formateDate); this.getContentPane().add(tfTime);
    this.pack();
    this.show();
        }
    public static void main(String[] args){
    showTime st = new showTime();
    }
    }
      

  5.   

    import java.util.*;
    import java.text.*;/**
     * <p>Title: </p>
     * <p>Description: </p>
     * <p>Copyright: Copyright (c) 2003</p>
     * <p>Company: </p>
     * @author not attributable
     * @version 1.0
     */public class TryDateFormate {
      public static void main(String[] args)
      {
        Date today = new Date();
        Locale[] locales = {Locale.US,Locale.UK,Locale.GERMANY,Locale.FRANCE };
        int[] styles = {DateFormat.FULL,DateFormat.LONG,DateFormat.MEDIUM,DateFormat.SHORT};
        DateFormat fmt;
        String[] styleText = {"FULL","LONG","MEDIUM","SHORT"};
        //output the date for each local in four styles
        for(int i = 0; i <  locales.length; i++)
        {
          System.out.println("\nThe Date for " + locales[i].getDisplayCountry() + ":");
          for (int j = 0; j <  styles.length; j++)
          {
            fmt = DateFormat.getDateInstance(styles[j],locales[i]);
            System.out.println("\t In " + styleText[j] + "is" + fmt.format(today));
          }
        }
      }}
    结果:
    The Date for 美国:
     In FULLisTuesday, August 5, 2003
     In LONGisAugust 5, 2003
     In MEDIUMisAug 5, 2003
     In SHORTis8/5/03
    The Date for 英国:
     In FULLis05 August 2003
     In LONGis05 August 2003
     In MEDIUMis05-Aug-2003
     In SHORTis05/08/03
    The Date for 德国:
     In FULLisDienstag, 5. August 2003
     In LONGis5. August 2003
     In MEDIUMis05.08.2003
     In SHORTis05.08.03
    The Date for 法国:
     In FULLismardi 5 ao?t 2003
     In LONGis5 ao?t 2003
     In MEDIUMis5 ao?t 2003
     In SHORTis05/08/03
      

  6.   

    public static String getSystemDate(String style) {
        
         if(!style.equals("yyyy/MM/dd") && !style.equals("yyyyMMdd")){
         style = "yyyy/MM/dd";
         }
        
     //カレント年/月/日取得
        GregorianCalendar gcdate=new GregorianCalendar();
         java.sql.Date edate = new java.sql.Date(gcdate.getTime().getTime());
         String curDate = SmtFunc.getDateString(edate, style);
        
         return   curDate;
        
    }
      

  7.   

    System.currentTimeMillis为当前时间毫秒数。