MS格式的Date转换为Json格式的Date 2010/01/04 No Comments

      在开发B/S项目时,使用到Ajax已经是司空见惯了,一般我们都是用Json作为数据传输的格式。

      在 .Net 中,我们可能用 Web Service 或者 WCF 来进行Json数据传输,这样传输到客户端的 Date 格式为:”\/Date(1231231323+0800)\/” 的字符串,这和Json的 Date 格式不一样,这样就可能导致服务器端与客户端的数据传输出错。 那么,这时我们就需要处理一个问题“MS格式的Date转换为Json格式的Date” 或者“Json格式的Date转换为MS格式的Date”。

      在解决这个问题前,先要知道 “\/Date(1231231323+0800)\/” 这个字符串代表了什么?其实这个字符串中 1231231323 是当前距离 1970 年 1 月 1 日之间的毫秒数,+0800 这个数字代表了时区,上面这个 MS 格式的日期字符串代表的是“Thu Jan 15 14:00:32 UTC+0800 1970”。

      好了,接下来就稍微容易理解了。在Javascript 中 Date 对象有个 getTime() 的方法返回 1970 年 1 月 1 日至今的毫秒数。于是,我们在向 WCF 提交日期数据的时候是需要把 Date 转换为 MS 的格式的字符串:

var date =new Date();
var dateStr = "\/Date("+date.getTime()+"+0800)\/"

而从 WCF 返回的 Json 数据,我们也要把 MS 的Date格式字符串转换成Json的Date格式 :

var msdateRe = /\/Date\((\d+)((\+|\-)\d+)?\)\//;  // MS JSON date format
if (o == undefined || o == null)
   return null;
if (o.substring(0, 1) == '/')
   if (o.match(msdateRe).length > 1) {
      return new Date(parseInt(o.replace(msdateRe, '$1')));
   }
return Date.parse(o);

over.

Theme widgets 的设置不能保存 No Comments

      我用的 wordpress2.9 英文版,刚刚换了皮肤,然后进widgets想设置下 sidebar 的内容,可是当我点击保存,系统就出错了 
Theme Widgets Saving Error

Theme Widgets Saving Error

403 - Forbidden: Access is denied.

You do not have permission to view this directory or page using the credentials that you supplied.

我用 godaddy 的 windows 主机,使用IIS7.0,不知道有没人遇到和我一样的问题???

CGUA.NET - Hosting Been Closed 1 Comment

Dec 31th, the last day of year 2009 evening, my website(cgua.net) couldn’t been reached…

I can’t resolve the problem, because Jan 1st, 2nd and 3rd was holidays of the New Year’s Day. What I can do just be waiting…

I contact my hosting provider(TODAYNIC.INC) this morning as soon as i arrived at the company, but the girl of TODAYNIC says that there were some keywords which had been forbidden by CNNIC(China Internet Network Information Center), and so I receive the bad news “The hosting was been closed!!!

But i’ve not post anything which is related to adult, anti-government or anything what had been forbidden by CNNIC,  I swear By God!

Now, they are close my hosting and there is no indication that they will re-open it for me…

So sad!

Hello world! No Comments

Welcome to Uvla.Net.  This is my new website.

My name is Jerrey Chen,  i was born in wenzhou china, and living in hangzhou china now.

Hangzhou, a very beautiful city.

Xihu Hangzhou

Xihu Hangzhou