转换DateTime [英] Conversion of DateTime

查看:66
本文介绍了转换DateTime的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HI全部,







我需要一些帮助。



i有两个字符串用于日期和一个用于时间我已将它们连接起来获取日期时间之后我已经使用所有方法转换我的日期时间字符串的日期时间格式但不幸的是转换是在我当地工作,但当我在uat环境中发布时,它无法正常工作



所以最后我的日期时间在本地系统工作但是相同是代码在服务器机器上无法工作...



HI All,



I need a small help.

i have two strings one for date and one for time i have concatenated them to get the datetime and after that i have used all the methods to convert my datetime string in datetime format but unfortunately that conversion is working in my local but when i made the release in uat environment then it is not working properly wat to do

so finally my datetime is working in local system but the same is code is not working in server machine wat to dooo...

var provider = CultureInfo.CurrentUICulture;
order1 = order.OrderDate + " " + order.OrderTime;
            delivery = order.DeliveryDate + " " + order.DeliveryTime;
            //order1 = string.Format("{0:dd-mm-yyyy HH:mm}", order1);
            //delivery = string.Format("{0:dd-mm-yyyy HH:mm}", delivery);
            string format = "yyyy-MM-dd HH:mm:ss";
            //DateTime.TryParseExact(order1,format,CultureInfo.InvariantCulture,DateTimeStyles.None, out o1);
            DateTime.TryParseExact(delivery,format,provider,DateTimeStyles.None, out d);
            //o1 = DateTime.ParseExact(order1, "yyyy-MM-dd HH:mm:ss", provider);
            //d = DateTime.ParseExact(delivery, "yyyy-MM-dd HH:mm:ss", provider);
            DateTime.TryParse(order1,out o1);
            d = DateTime.ParseExact(delivery, format, provider);
            item.orderDateTime = o1;

推荐答案

string order1 = "2013-04-01 01:00:00 pm";
string delivery = "2013-04-02 02:00:00 pm";
DateTime d;
DateTime o1;
DateTime.TryParse(delivery, out d);
DateTime.TryParse(order1, out o1);
Console.WriteLine(d);
Console.WriteLine(o1)
Console.WriteLine(d.ToString("yyyy-MM-dd HH:mm:ss"));
Console.WriteLine(o1.ToString("yyyy-MM-dd HH:mm:ss"));





收益此结果:



Yields this result:

4/2/2013 2:00:00 PM
4/1/2013 1:00:00 PM
2013-04-02 14:00:00
2013-04-01 13:00:00






您可以查看以下DateTime结构示例 -



Hi,

You can check with following DateTime constructure example --

System.Globalization.CultureInfo info =
    new System.Globalization.CultureInfo("en-US", false);

System.Globalization.Calendar calendar = info.Calendar;

System.DateTime dateTime = 
    new System.DateTime(1979,        // Year
                        07,            // Month
                        28,            // Day
                        22,            // Hour
                        35,            // Minute
                        5,            // Second
                        15,            // Millisecond
                        calendar    // Calendar
                        );


这篇关于转换DateTime的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆