我有一个字符串“ 2017-01-05T15:03:25.21”,它已经是我所在时区的确切时间。(例如:+8)如何将此字符串转换为Date对象?提出此问题的原因是,Date类似乎仅接受“ UTC日期字符串”。如果我直接这样做:
var strDateTime = "2017-01-05T15:03:25.21";
var myDate = new Date(strDateTime);
//myDate will have another redundant time-zone offset.
Run Code Online (Sandbox Code Playgroud)
如何正确转换呢?
我希望我的解释是正确的。
我有 2 张桌子,
第一个表 ( table1)
+------------+------+-------+-------+
| Date | Item | Block | Total |
+------------+------+-------+-------+
| 2017-01 | a1 | B1 | 10.0 |
| 2017-01 | a2 | B1 | 20.0 |
| 2017-01 | a3 | B2 | 30.0 |
| 2017-02 | a1 | B1 | 40.0 |
| 2017-02 | a2 | B1 | 50.0 |
| 2017-02 | a3 | B2 | 60.0 |
+------------+------+-------+-------+
Run Code Online (Sandbox Code Playgroud)
第二个表 ( table2)
+------------+------+
| …Run Code Online (Sandbox Code Playgroud) 在 C# 中,我需要创建一个返回一个对象的函数,该对象可能包括:
{ itemID: "A1", itemDesc: "apple" }
Run Code Online (Sandbox Code Playgroud)
或者
{ groupID: "G1", groupDesc: "group1" } ..etc
// Please don't be concerned about why don't create another function for this,
// or why don't consider 'ID' instead.
Run Code Online (Sandbox Code Playgroud)
我好奇。原因是,这在 javascript 中很简单,因为您可以将任何键分配给一个对象,而无需预先定义它。
然而,当谈到 C# 时,我感到困惑。
这可能吗?
编辑:
对不起,我应该更清楚地说明问题(所以它可能不是“重复”)
我的函数实际上返回一个类,如下所示:
public class MyClass
{
public int myKey {get;set;}
public List<customClass> listRecord {get;set;}
}
Run Code Online (Sandbox Code Playgroud)
这customClass是我所指的动态“对象”。请注意,记录是从 LINQ 查询的。
感谢您的建议,但我似乎无法做到这一点:
var result = (from a in db.MyTable
select new System.Dynamic.ExpandoObject()
{
....
Run Code Online (Sandbox Code Playgroud)
我也不能 select …