关于系统时间和类型转换的问题!!在线等!!!急!!!

Explorer22 2003-08-21 11:17:41
1,如何得到系统的当前时间,只要得到年,月,日;
2,如何将上面得到的时间转换为字符串类型!!!
新手一个,又没有资料查,大家帮忙了,在线等!!!急!!!
最好给个例子!!!
...全文
113 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
zeros 2003-08-22
  • 打赏
  • 举报
回复
贴出这么多代码谁看啊!你自己一点都不会,还当什么程序员啊!
Explorer22 2003-08-22
  • 打赏
  • 举报
回复
to: diewikwang(coconut)我用String type = mySmartUpload.getRequest("Type");后报错如下:
Note: sun.tools.javac.Main has been deprecated.
/programe/uploadFile/upload.jsp:21: Wrong number of arguments in method.
String type = mySmartUpload.getRequest("Type");
^
Note: E:\resin\doc\WEB-INF\work\_programe\_uploadfile\_upload__jsp.java
uses or overrides a deprecated API. Recompile with "-deprecation" for
details.
是什么原因啊,该如何解决啊???
我已经import="com.jspsmart.upload.*“
帮帮忙!!!先谢了!!!
diewikwang 2003-08-22
  • 打赏
  • 举报
回复
其实是这样,加了那句东东以后,如果form的 method="post"的话,你form里面的东西request就得不到了,如果method="get"的话你又没法得到你想upload的文件。
smartupload里面做了一个Request类来代替原来的jsp里面的request,用来得到form里面
的值,用这个其实是最好的。如果你实在不肯用,也有个比较恶心的方法,就是在form里面
加一个onsubmit="javascript:submitForm();",然后在submitForm里面把你form中全部的
输入值都输到form的action后面,不过不提倡这种办法。我想你还是老老实实看看怎么得到
那个Request吧,呵呵
Explorer22 2003-08-22
  • 打赏
  • 举报
回复
to fangzn(fangzn)
谢谢指教,新手一个还不知道什么规范!!!!
还望今后多指教!!!!
Explorer22 2003-08-22
  • 打赏
  • 举报
回复
to diewikwang(coconut) 在Form中的值不能用“在url后面的值(比如xxx.jsp?aaa=aaa就可以接到)”来得到啊!!!
那Form中的值可以用什么得到呢???
fangzn 2003-08-22
  • 打赏
  • 举报
回复
TO: Explorer22()

这么写不太好吧??java的代码尽量少放在JSP里吧?
Explorer22 2003-08-22
  • 打赏
  • 举报
回复
to diewikwang(coconut) I try!!!!
Thank you very much!!!!!!
diewikwang 2003-08-22
  • 打赏
  • 举报
回复
在form里面指定了 ENCTYPE="multipart/form-data" 以后,request.getParameter得到地全部都是null,除非是直接跟在url后面的值(比如xxx.jsp?aaa=aaa就可以接到)。在jspsmartupload里面有一个Request类,里面有getParameter, getParameterValues等等方法,你需要用这个类来得到你传过来地值。
至于这个类地实例怎么得到具体我是记不起来了,
好象是mySmartUpload.getRequest()吧,你自己javap一下,最近跳槽了,代码都留在
原来地公司一点没带走。
Explorer22 2003-08-22
  • 打赏
  • 举报
回复
各位帮忙看一下:
第一个页面的代码:upload1.jsp

<%@ page contentType="text/html; charset=gb2312"
import="java.util.Date ,java.io.*,java.lang.*,java.text.SimpleDateFormat"%>
<HTML>
<BODY BGCOLOR="white">

<H1 align="center">图片、电影、音乐、新闻上传</H1>
<HR>

<FORM METHOD="POST" ACTION="/programe/uploadFile/upload.jsp" ENCTYPE="multipart/form-data">
<select name="Type" size="1" > //*****这是要传送的值“Type"********
<%

String path="";

path = request.getRealPath("./");

File d = new File(path);
//建立代表目前目录位置的File件, 并由d件变数引用

File list[] = d.listFiles();
//取得代表目录中所有文件的File件阵列
int j=list.length-3;
int i =0;
while(j>0)
{

%>
<option value="<%=list[i]%>"><%=list[i]%></option>
<%
i++;
j--;
}
%>
</select>
<select name="Year" size="1">
<%
Date today = new Date();
SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
String sToday = format.format(today);
int lToday = Integer.parseInt(sToday);
int w = lToday%10000;
int ww=(lToday-w)/10000;

%>
<option value="<%=String.valueOf(ww)%>"><%=String.valueOf( ww)%></option>
</select>
<select name="Month" size="1">
<%
for(int month=1;month<=12;month++)
{
%>
<option value="<%=String.valueOf(month)%>"><%=String.valueOf( month)%></option>
<%
}
%>
</select>
<select name="Day" size="1">
<%
for(int day=1;day<=31;day++)
{
%>
<option value="<%=String.valueOf(day)%>"><%=String.valueOf(day)%></option>
<%
}
%>
</select>

<br>
<INPUT TYPE="FILE" NAME="FILE1" SIZE="50"><BR>
<INPUT TYPE="FILE" NAME="FILE2" SIZE="50"><BR>
<INPUT TYPE="FILE" NAME="FILE3" SIZE="50"><BR>
<INPUT TYPE="FILE" NAME="FILE4" SIZE="50"><BR>
<INPUT TYPE="SUBMIT" VALUE="Upload">
</FORM>

</BODY>
</HTML>

第二个页面的代码:upload.jsp
<%@ page contentType="text/html; charset=gb2312" language="java"
import="com.jspsmart.upload.*,java.io.File,java.lang.*,java.util.Date,java.text.SimpleDateFormat"%>
<jsp:useBean id="mySmartUpload" scope="page" class="com.jspsmart.upload.SmartUpload" />


<HTML>
<head>
<title>Images,Movies,Music,News UpLoaded</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">

</head>

<BODY BGCOLOR="white">

<H1 align="center">Images,Movies,Music,News UpLoaded</H1>
<HR>

<%

String type = request.getParameter("Type"); //********这是接收这个传送的值**
//String year = request.getParameter("Year");
//String month =request.getParameter("Month");
//String day = request.getParameter("Day");
out.println(type);

String path="";

path = request.getRealPath("./");

File d = new File(path);
//建立代表目前目录位置的File件, 并由d件变数引用

File list[] = d.listFiles();
//取得代表目录中所有文件的File件阵列
%>

<%
// Variables
int count=0;

// Initialization
mySmartUpload.initialize(pageContext);

// Only allow txt or htm files
mySmartUpload.setAllowedFilesList(" gif,jpg,swf,txt");

// DeniedFilesList can also be used :
// mySmartUpload.setDeniedFilesList("exe,bat,jsp");

// Deny physical path
// mySmartUpload.setDenyPhysicalPath(true);

// Only allow files smaller than 2000000 bytes
mySmartUpload.setMaxFileSize(2000000);

// Deny upload if the total fila size is greater than 800000 bytes
mySmartUpload.setTotalMaxFileSize(800000);

// Upload
mySmartUpload.upload();

//look for file path ,if there is nothing ,create file path
File myFilePath = new File(type);
if(!myFilePath.exists())
myFilePath.mkdir();

String nextFilePath="";
nextFilePath = request.getRealPath("myFilePath/");


Date today = new Date();
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
String sToday = format.format(today);



String fileName =sToday;
File myFile = new File(nextFilePath+"/"+fileName);
if(!myFile.exists())
myFile.mkdir();
String filePath = nextFilePath+"/"+fileName;

// Save the files with their original names in a virtual path of the web server
try {

count = mySmartUpload.save(filePath, mySmartUpload.SAVE_VIRTUAL);

} catch (Exception e){

out.println("<b>Wrong selection : </b>" + e.toString());

}

// Display the number of files uploaded
out.println(count + " file(s) uploaded.");

%>


<table width="85%" border="0" cellpadding="3" cellspacing="0">
<tr>
<td colspan="8">在<Font color = red><%= path%></Font>目录下的文件 一共有 <font color="#FF0000"><%=list.length%></font>
个文件或目录  <a href="javascript:history.back(1)">返回</a>   <a href="javascript:location.reload()">刷新</a> </td>
</tr>
</table>
<hr>

<table width="1000" height="150"border="0" align="center" cellpadding="3" cellspacing="0">
<%
for(int i=0; i <list.length/5; i++)
{
%>
<tr >
<%
for(int j=0;j<5;j++)
{
File f = new File(path,list[i*5+j].getName());
String file="";

file=list[i*5+j].getName();

//out.print(file.toString());
%>
<td align="center" width="120" height="150">
<a href="<%=file%>" target="_self"><img src="<%=file%>" width="120" height="150" name="<%=file.toString()%>" title="<%=file.toString()%>" ></a>
<a href="<%=file%>" target="_parent"><%=file%></a>
</td>
<%
}
%>
</tr>
<%
}
%>
</table>
<BR>
<a href="javascript:history.back(1)">Back</a>
</BODY>
</HTML>
大家帮忙看看为什么传过来的值接收后为空????在线等!!!!急啊!!!!!!!!!!!!


TomClus8888 2003-08-21
  • 打赏
  • 举报
回复
long lngBeginTime = System.currentTimeMillis();
System.out.println(":Create Object: "+ String.valueOf(System.currentTimeMillis() -lngBeginTime));
TomClus8888 2003-08-21
  • 打赏
  • 举报
回复
Calendar cBegin = Calendar.getInstance();
StringBuffer sb = new StringBuffer();
sb.append(String.valueOf(nPageID)+ "Begin Time:"+cBegin.get(cBegin.YEAR)+"/");
sb.append(cBegin.get(cBegin.MONTH)+"/");
sb.append(cBegin.get(cBegin.DAY_OF_MONTH)+" ");
sb.append(cBegin.get(cBegin.HOUR_OF_DAY)+":");
sb.append(cBegin.get(cBegin.MINUTE)+":");
sb.append(cBegin.get(cBegin.SECOND)+":");
sb.append(cBegin.get(cBegin.MILLISECOND));
System.out.println(sb.toString());
whyxx 2003-08-21
  • 打赏
  • 举报
回复
Date bb = Calendar.getInstance().getTime();
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
String sToday = format.format(today);
System.out.println(sToday);
lkenshin 2003-08-21
  • 打赏
  • 举报
回复
下载地址:

http://java.sun.com/webapps/download/Redirect/69993992/5847479377282807053505607246086069333228071972022813600060192859339008063305596058473206-3866/j2sdk-1_4_2-doc.zip
lkenshin 2003-08-21
  • 打赏
  • 举报
回复
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateTest {
public static void main(String[] args){
Date today = new Date();
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
String sToday = format.format(today);
System.out.println(sToday);
}
}

你可以去下载一个java aip doc 对你有帮助
freelarry 2003-08-21
  • 打赏
  • 举报
回复
你有个参数的值是null,你自己看看程序吧
Explorer22 2003-08-21
  • 打赏
  • 举报
回复
在问大家一个问题!!!
500 Servlet Exception
java.lang.NullPointerException
at java.io.File.<init>(File.java:180)
at _programe._uploadfile._upload__jsp._jspService (/programe/uploadFile/upload.jsp:47)
at com.caucho.jsp.JavaPage.service(JavaPage.java:75)
这样的异常怎么解决???由什么引起的,应该怎么着手解决???
我用的是resin,请各位帮忙了!!!!


Explorer22 2003-08-21
  • 打赏
  • 举报
回复
Thanks every one!!!

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧