是否有任何库来解析像“DateTime.Now()”这样的字符串。进入Silverlight的DateTime / [英] Is there any library to parse strings like "DateTime.Now() " into DateTime for Silverlight/

查看:57
本文介绍了是否有任何库来解析像“DateTime.Now()”这样的字符串。进入Silverlight的DateTime /的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有任何库可以解析像"DateTime.Now()"这样的字符串。进入Silverlight的DateTime?

Is there any library to parse strings like "DateTime.Now() " into DateTime for Silverlight?

我们无法在运行时编译字符串,因为编译器类具有对Silverlight的有限访问权限。

We cannot Compile the string at runtime , since Compiler class has  limited access for Silverlight.

Thanx并关注

Amarnath Panda

Amarnath Panda

推荐答案



您好Amarnath Panda,


Hi Amarnath Panda,

>>是否有任何库可以解析像"DateTime.Now()"这样的字符串。进入Silverlight的DateTime?

据我所知,.NET框架没有用于解析像"DateTime.Now()"这样的字符串的库。进入DateTime。

As far as I know, , NET framework does not have the library to parse strings like "DateTime.Now() " into DateTime.

我们将使用以下代码将字符串解析为DateTime。

We will use the following code to parse strings into DateTime.

DateTime.ParseExact Method(String,String,IFormatProvider)

https://msdn.microsoft.com/ en-us / library / w2sa9yss(v = vs.110).aspx

DateTime.ParseExact Method (String, String, IFormatProvider)
https://msdn.microsoft.com/en-us/library/w2sa9yss(v=vs.110).aspx

如果您需要处理特殊字符,可以自定义扩展方法来处理它。

If you need to deal with your special characters, you can customize the extension method to handle it.


 DateTime dt2= (DateTime)MoreConvert.ToDateTimeOrNull("DateTime.Now()");

 public static class MoreConvert
    {
        public static DateTime? ToDateTimeOrNull(string text)
        {
            return text == null || text != "DateTime.Now()" ? (DateTime?)null : DateTime.Now;
        }
    }

最好的问候,

Yohann Lu

Yohann Lu


这篇关于是否有任何库来解析像“DateTime.Now()”这样的字符串。进入Silverlight的DateTime /的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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