2016-05-19 1 views
1

私はdatetime変数から時刻を取得しようとしていますが、いくつか問題があります。 日付を.ToShortTimeStringを使って私のウェブの時間だけを取得しようとしています。Api - 動作しません。

[HttpGet] 
public IHttpActionResult GetPostedTime(){ 
    var gettime = 
     context.table.where(x => x.username == "some user") 
        .select(x => 
         new { 
          x.Id, 
          x.username, 
          x.DatePosted.ToshortTimeString() // try to get the time only here but getting  //error - ​*anonymous type projection initializer should be simple name*​ 
         }); 
    return gettime; 
} 

は私が唯一の私のdatetime変数からの時間を得ることができるか、私はどのように修正する可能性のある簡単な方法があります:私はこのようなメソッドを持って、その後

public class table{  
    public int Id {get;set;} 
    public string username {get; set;} 
    public DateTime DatePosted {get;set;}  
} 

: 私はこのようなモデルを持っていますエラーと時間だけを取得します。 あなたが

答えて

3

あなたはしかし、DatePosted` `のための唯一の真の名前

var gettime = context.table.where(x => x.username == "some user").select(x => new { 
    Id = x.Id, 
    username = x.username, 
    DatePosted = x.DatePosted.ToshortTimeString() 
}); 
+3

を指定する必要がありますありがとうございました。 'Id'と' username'は引き続き推定できます。しかし、おそらくあなたは一貫していただけだった。私は気にしない。 –

関連する問題