如果你的表里只有一个 那么使用以下公式。
=LEFT(RIGHT(A2,LEN(A2)-FIND("",A2)),LEN(RIGHT(A2,LEN(A2)-FIND("",A2)))-4)
或者
=LEFT(RIGHT(A2,LEN(A2)-FIND("",A2)),LEN(RIGHT(A2,LEN(A2)-FIND("",A2)))-(LEN(A2)-FIND("jpg",A2)+1))
首先使用函数FIND() 分别求出 出现的位置。
然后使用函数计算出LEN() 计算出字符串的总长度。
之后再使用函数RIGHT()求出 之后的字符串。
=RIGHT(A2,LEN(A2)-FIND("",A2)) 得出 之后的字符串,最后取得4位的jpg
最后使用函数LEFT()截取jpg 即可。
public Date parse(String text,
ParsePosition pos)解析字符串的文本,生成 Date。
此方法试图解析从 pos 给定的索引处开始的文本。如果解析成功,则将 pos 的索引更新为所用最后一个字符后面的索引(不必对直到字符串结尾的所有字符进行解析),并返回解析得到的日期。更新后的 pos 可以用来指示下次调用此方法的起始点。如果发生错误,则不更改 pos 的索引,并将 pos 的错误索引设置为发生错误处的字符索引,并且返回 null。
指定者:
类 DateFormat 中的 parse
参数:
text - 应该解析其中一部分的 String。
pos - 具有以上所述的索引和错误索引信息的 ParsePosition 对象。
返回:
从字符串进行解析的 Date。如果发生错误,则返回 null。
抛出:
NullPointerException - 如果 text 或 pos 为 null。
用这个方法
public static Date StringToDate(String dateStr,String formatStr){
DateFormat dd=new SimpleDateFormat(formatStr);
Date date=null;
try {
date = ddparse(dateStr);
} catch (ParseException e) {
eprintStackTrace();
}
return date;
}
java中将字符串转换成日期类型,可以使用SimpleDateFormat日期转换类,有一个前提是字符串必须满足日期的格式,如果不是会有异常,示例如下:
package comqiulinhe;import javatextParseException;
import javatextSimpleDateFormat;
import javautilDate;
public class CeShi {
public static void main(String[] args) {
String dateStr = "2010-10-11 10:00:02";
try {
Date d = parseDate(dateStr);//将字符串转换成date类型
Systemoutprintln(d);
} catch (ParseException e) {
// TODO Auto-generated catch block
eprintStackTrace();
}
}
//将字符串转换成date类型方法
static public Date parseDate(String s) throws ParseException {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
return formatparse(s);
}
}
结果是:
Mon Oct 11 00:00:00 CST 2010
这个问题很明显是TextBoxText的值为空或者非数字字符串所以用ConvertToInt32()的时候会报错
建议自己写个函数来转换
int strtr = ConvertToInt(tb1Text)
int strjl = ConvertToInt(tb2Text)
int strsy = ConvertToInt(tb3Text)
private int ConvertToInt(string InStr)
{
try
{
return ConvertToInt32(InStr);
}
catch
{
return 0; //转换错误返回 0
}
}
import javatextSimpleDateFormat;
import javautil;
public class getDate {
public static void main(String []args){
// SimpleDateFormat formater=new SimpleDateFormat("MM月dd日yyyy年");调整格式
SimpleDateFormat formater=new SimpleDateFormat("yyyy年MM月dd日");
String StCurrentTime=formaterformat(new Date());
Systemoutprint( StCurrentTime);
}
}
根据查找到字符串中 '\0'字符的位置结束 '\0' 前面的个数为该字符串长度 比如 "hello world!" 字符串长度为12 (字符串存储时结尾自动加上\0字符) 如果这样写 "hello \0world!" 字符串长度为6 (空格也算一个字符)
换成下面的看看
cboYearText = mydtYearToString();
cboMothText= mydtMonthToString();
cboDayText = mydtDayToString();
假定你从串口中读到的数据,每次读一行,并存到一个字符串中。
然后调用这样的函数:
typedef strcut{
char week[5];
int day;
char month[5];
int year;
int h,m,s;
}date;
int parse(char s, date time)
{
if(strncmp(s, "Date:",5) !=0) return -1;
if(sscanf(s+5, "%s%d%s%d%d:%d:%d", time->week, &time->day, time->month, &time->year, &time->h,&time->m, &time->s)!=7)
return -2;
return 0;
}
如果必要,可以在比较month和week的值,转为整型。
以上就是关于excel取不规则字符串中的日期全部的内容,包括:excel取不规则字符串中的日期、java 字符串转换成日期、java中如何将字符串转换成日期型等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)