1、
字符串转换成日期时间格式
   //日期时间格式:yyyy-MM-dd hh:mm:ss
    String time ="1900-02-21 12:23:33";
    //将字符串转换为日期和时间
    SimpleDateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
    //生成的日期和时间
    Date date = dateformat .parse(time);
 
date就是我们想要的 
 
如果程序中有2个或2个以上的地方调用了dateformat.parse()方法,则有可能会报错:Unhandled exception type ParseException。
为此,需要利用try-catch块来捕捉:
  try{
            dateformat .parse(time);
        } catch(Exception e) {
            e.printStackTrace();
        } 
 
http://www.cnblogs.com/pricks/archive/2009/06/05/1497193.html
2、
字符串转换为日期型(C#)
如:"20071107"转换成日期型?
"20071107"转换成int型怎么转换??
1、DateTime dt=Convert.ToDateTime("20071107".Substring(0,4)+"-"+"20071107".Substring(4,2)+"-"+"20071107".Substring(6,2)); 
int i=Convert.ToInt32("20071107");
2、Convert.ToDateTime、DateTime.Parse()
3、string str = "20071107";
DateTime dt = DateTime.ParseExact(str, "yyyyMMdd", null);
int i;
int.TryParse(str, out i);
4、定义一个DateTimePicker对象,然后将需要转化的字符串赋给这个DateTimePicker对象的Text属性, 
然后DateTimePicker对象的Value值就是你需要的日期和时间,Value值还有Minite,Second等属性,可以取得 
时,分,秒,豪秒等值. 
http://hi.baidu.com/sunygis/blog/item/e3bb13faa0f449116d22eb8a.html
上一篇:从表中取出某年或某月的数据
相关新闻
- 小程序登录流程图理解 2020-08-18
- 在C#中获取web.config中的配置信息 2021-08-23
- 小程序open-data头像样式 2021-04-10
- 小程序rich-text 富文本解析图片过大和图片路径的问题 2020-11-25
- C#中去掉字符串的最后一个字符 2020-11-23
 
                 
                                                 
                                                 
                                                 
                                                 
                                                 
                                                 
                                                 
                                                 
                                                 
                                                 
                                                 
                                                 
                                                 
                                                
 
                        
                    
