如何使用csharp从Windows Phone 8设备获取DateTime [英] How to get DateTime from windows phone 8 device using csharp

查看:122
本文介绍了如何使用csharp从Windows Phone 8设备获取DateTime的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有unix时间戳.我已经转换为dateTime.现在我想从当前设备的dateTime中减去它.我该如何在csharp中进行操作.

I have unix timestamp.I have converted to dateTime.Now i want to subtract it from current device dateTime.How can i do in csharp.

我有以下代码 将Unix时间戳转换为dateTime:

I have following code  which converts unix timestamp to dateTime:

System.DateTime dtDateTime =新的DateTime(1970,1,1,0,0,0,0);
            dtDateTime = dtDateTime.AddSeconds(Convert.ToDouble(showTime.Text)).ToLocalTime();

System.DateTime dtDateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0);
            dtDateTime = dtDateTime.AddSeconds(Convert.ToDouble(showTime.Text)).ToLocalTime();

我还想显示时间,例如"1小时前","2周前","1个月前".c Sharp是否有任何可用的函数,因此它将直接为我提供这种类型的dateTime

I also want to show time in like '1 hours ago', '2 weeks ago','1 month ago'.Is there any functions available in c sharp so it will directly give me such type of dateTime

推荐答案

您可以简单地将其减去,该操作将为您提供一个这样的时间跨度:

You can simply subtract it, that operation will give you a timespan like this:

TimeSpan ts = (DateTime.Now - dtDateTime );

之后,您可以使用ts做任何您想做的事,例如:

After that you can use the ts to do whatever you want, for example:

string.Format("{0} hours ago", ts.Hours);



这篇关于如何使用csharp从Windows Phone 8设备获取DateTime的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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