String str = "2002/4/22";
str = str.replace('/','');
str = str.replace('/','');
解决方案 »
- java读取注册表中word的路径
- java里有多少个类加载器
- 怎样把String转换为URL类?
- 如何在一个frame底部增加windows程序所常见的那种状态条?
- 初学java,简单问题请教!
- 幫忙看看這樣簡單的錯誤 :ClassNotFoundException 在線等後
- 2003 server 下安装了j2sdk-1_4_1_03-windows-i586之后,双击执行.jar文件为什么一闪而过,XP下却正常运行?
- tomcat under linux
- ----------------jdk1.3编程环境的设置问题----------------
- 用什么JAVA软件可能建立和打开*.class文件?最好是小软件。哪里有下载?
- 帮忙啊!大哥,我给分
- 为什么会这样??急急……
private int year;
private int month;
private int day; .... public String printYearMonthDay() {
在此需要用 year,month, day,来构造YYYYMMDD格式的字符串(如:20020501)
}请问有没有现成的包?具体那个包那个方法?谢谢!
里面有很多东西
java.text.*
* 根据pattern指定的样式转换格式的日期
* @param date 要转换的日期
* @param pattern 要指定的得日期格式
* @return String
* @throws IllegalArgumentException 当两个参数出错时抛出此异常<br>
*
* 下为日期格式的简单描述详情请参看javaApi中java.text.SimpleDateFormat<br>
* The following pattern letters are defined (all other characters from
* <code>'A'</code> to <code>'Z'</code> and from <code>'a'</code> to
* <code>'z'</code> are reserved):
* <blockquote>
* <table border=0 cellspacing=3 cellpadding=0>
* <tr bgcolor="#ccccff">
* <th align=left>Letter
* <th align=left>Date or Time Component
* <th align=left>Presentation
* <th align=left>Examples
* <tr>
* <td><code>G</code>
* <td>Era designator
* <td><a href="#text">Text</a>
* <td><code>AD</code>
* <tr bgcolor="#eeeeff">
* <td><code>y</code>
* <td>Year
* <td><a href="#year">Year</a>
* <td><code>1996</code>; <code>96</code>
* <tr>
* <td><code>M</code>
* <td>Month in year
* <td><a href="#month">Month</a>
* <td><code>July</code>; <code>Jul</code>; <code>07</code>
* <tr bgcolor="#eeeeff">
* <td><code>w</code>
* <td>Week in year
* <td><a href="#number">Number</a>
* <td><code>27</code>
* <tr>
* <td><code>W</code>
* <td>Week in month
* <td><a href="#number">Number</a>
* <td><code>2</code>
* <tr bgcolor="#eeeeff">
* <td><code>D</code>
* <td>Day in year
* <td><a href="#number">Number</a>
* <td><code>189</code>
* <tr>
* <td><code>d</code>
* <td>Day in month
* <td><a href="#number">Number</a>
* <td><code>10</code>
* <tr bgcolor="#eeeeff">
* <td><code>F</code>
* <td>Day of week in month
* <td><a href="#number">Number</a>
* <td><code>2</code>
* <tr>
* <td><code>E</code>
* <td>Day in week
* <td><a href="#text">Text</a>
* <td><code>Tuesday</code>; <code>Tue</code>
* <tr bgcolor="#eeeeff">
* <td><code>a</code>
* <td>Am/pm er
* <td><a href="#text">Text</a>
* <td><code>PM</code>
* <tr>
* <td><code>H</code>
* <td>Hour in day (0-23)
* <td><a href="#number">Number</a>
* <td><code>0</code>
* <tr bgcolor="#eeeeff">
* <td><code>k</code>
* <td>Hour in day (1-24)
* <td><a href="#number">Number</a>
* <td><code>24</code>
* <tr>
* <td><code>K</code>
* <td>Hour in am/pm (0-11)
* <td><a href="#number">Number</a>
* <td><code>0</code>
* <tr bgcolor="#eeeeff">
* <td><code>h</code>
* <td>Hour in am/pm (1-12)
* <td><a href="#number">Number</a>
* <td><code>12</code>
* <tr>
* <td><code>m</code>
* <td>Minute in hour
* <td><a href="#number">Number</a>
* <td><code>30</code>
* <tr bgcolor="#eeeeff">
* <td><code>s</code>
* <td>Second in minute
* <td><a href="#number">Number</a>
* <td><code>55</code>
* <tr>
* <td><code>S</code>
* <td>Millisecond
* <td><a href="#number">Number</a>
* <td><code>978</code>
* <tr bgcolor="#eeeeff">
* <td><code>z</code>
* <td>Time zone
* <td><a href="#timezone">General time zone</a>
* <td><code>Pacific Standard Time</code>; <code>PST</code>; <code>GMT-08:00</code>
* <tr>
* <td><code>Z</code>
* <td>Time zone
* <td><a href="#rfc822timezone">RFC 822 time zone</a>
* <td><code>-0800</code>
* </table>
* </blockquote>
*<h4>Examples</h4>
*
* The following examples show how date and time patterns are interpreted in
* the U.S. locale. The given date and time are 2001-07-04 12:08:56 local time
* in the U.S. Pacific Time time zone.
* <blockquote>
* <table border=0 cellspacing=3 cellpadding=0>
* <tr bgcolor="#ccccff">
* <th align=left>Date and Time Pattern
* <th align=left>Result
* <tr>
* <td><code>"yyyy.MM.dd G 'at' HH:mm:ss z"</code>
* <td><code>2001.07.04 AD at 12:08:56 PDT</code>
* <tr bgcolor="#eeeeff">
* <td><code>"EEE, MMM d, ''yy"</code>
* <td><code>Wed, Jul 4, '01</code>
* <tr>
* <td><code>"h:mm a"</code>
* <td><code>12:08 PM</code>
* <tr bgcolor="#eeeeff">
* <td><code>"hh 'o''clock' a, zzzz"</code>
* <td><code>12 o'clock PM, Pacific Daylight Time</code>
* <tr>
* <td><code>"K:mm a, z"</code>
* <td><code>0:08 PM, PDT</code>
* <tr bgcolor="#eeeeff">
* <td><code>"yyyyy.MMMMM.dd GGG hh:mm aaa"</code>
* <td><code>02001.July.04 AD 12:08 PM</code>
* <tr>
* <td><code>"EEE, d MMM yyyy HH:mm:ss Z"</code>
* <td><code>Wed, 4 Jul 2001 12:08:56 -0700</code>
* <tr bgcolor="#eeeeff">
* <td><code>"yyMMddHHmmssZ"</code>
* <td><code>010704120856-0700</code>
* </table>
* </blockquote>
*/
public static String trimFormat(Date date,String pattern) throws IllegalArgumentException {
if(date==null)
throw new IllegalArgumentException("date");
if(pattern==null)
throw new IllegalArgumentException("format");
SimpleDateFormat objSDateFormat= new SimpleDateFormat(pattern);
return objSDateFormat.format(date);
}
}
import java.text.*;....
java.util.Date dtCallTime = new java.util.Date();
SimpleDateFormat simDate = new SimpleDateFormat ("yyyyMMddHHmmss");
String strReturn = simDate.Format(dtCallTime);
<%
String today=new String();
{
String da=(new java.util.Date()).toString();
String[] month={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
String tomonth=da.substring(4,7); //month
today=da.substring(24,28)+"-"; //store the year and separater
for(int k=0;k<12;k++)
{
if(tomonth.equals(month[k]))
{
if(k<9)
today+="0"; //to standard month form
today+=String.valueOf(k+1); //store the month
today+="-";
break;
}
}
today+=da.substring(8,11); //store the day with space at the end
today+=da.substring(11,19); //store the time
}
%>