Datacontractjsonserializer and datetime

Source: Internet
Author: User
Tags epoch time tojson unix epoch time

UseWhen datacontractjsonserializer serializes datetime, it uses datetime. ticks to convert the Unix timestampe mode.

It should be noted that it takes only a few milliseconds. If you use PHP or other languages for parsing, You need to perform a 1000 conversion. For example:

 

Echo   Time (); // Get it in PHPUNIX epoch time
Echo   Date ( ' Y-m-d h: I: S ' , 1258698799374 / 1000 + 60 * 60 * 8 ); // Convert epoch time in PHP

 

Paste it by the wayUse of datacontractjsonserializer:

Code ClassProgram

{
Static   Void Main ( String [] ARGs)
{
Console. writeline (tojson (datetime. parse ( " 2009-11-20 " )));
Console. writeline (tojson (datetime. Now. ticks ));

Console. readkey ();
}

Public   Static   String Tojson ( Object Value)
{
VaR Ser =   New Datacontractjsonserializer (value. GetType ());
VaR MS. =   New Memorystream ();
Ser. writeobject (MS, value );
Return Encoding. Default. getstring (Ms. toarray ());
}
}

 

Ref: http://www.epochconverter.com /#

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.