请问parsePosition是干啥用的?谢谢

sssslssssl 2005-03-25 08:44:09
String strDate = “Fri Mar 25 20:41:39 CST 2005”;
ParsePosition pp = new ParsePosition( 0 );
Date dd = sdf.parse(strDate , pp);
System.out.println( dd );

输出:Fri Mar 25 20:41:39 CST 2005

若将参数index“0”改为“1”
则输出:Wed Mar 25 20:41:39 CST 2005

怎么回事啊?谢谢
...全文
5038 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
sssslssssl 2005-03-26
  • 打赏
  • 举报
回复
谢谢,懂了,用来标明解析开始位,其实也可以不明传pos的,呵呵
kingfish 2005-03-25
  • 打赏
  • 举报
回复
如果是“1”,那就不是2005年,而是5年了
angues1980 2005-03-25
  • 打赏
  • 举报
回复
The method attempts to parse text starting at the index given by pos. If parsing succeeds, then the index of pos is updated to the index after the last character used (parsing does not necessarily use all characters up to the end of the string), and the parsed date is returned. The updated pos can be used to indicate the starting point for the next call to this method. If an error occurs, then the index of pos is not changed, the error index of pos is set to the index of the character where the error occurred, and null is returned.
大概的意思是用来建立指向String转换为Date()时的索引位置。
ParsePosition pp = new ParsePosition( 0 );就是从String第0个字符位置开始parse,1的话就是从第一个字符位置开始parse吧
kingfish 2005-03-25
  • 打赏
  • 举报
回复
Date dd = sdf.parse(strDate , pp);
---
从pp开始解析

62,614

社区成员

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

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