Python conversion implementation code for time between various languages

Source: Internet
Author: User
a basic knowledge

Millisecond MS
Microsecond μs
Nanosecond nanoseconds
1 sec =1000 msec 1 msec =1000 microseconds 1 μs =1000 nanoseconds

Two Perl

In Perl, you can use time or localtime to get the times, the number of seconds to return from 0 o'clock January 1, 1970, localtime to return a string representation of the current time, or a tuple representation of a month or date.

#!/usr/bin/perluse strict;use warnings;use POSIX qw (strftime); # seconds from 1970.01.01 00:00:00my $ti = time ();p rint $ti; print "\ n";p rint strftime ("%y-%m-%d%h:%m:%s\n", LocalTime ($ti)), #1310623469 #2011-07-14 14:03:58my $t = localtime (); Print $t;p rint "\ n"; #Thu Jul 12:25:16 2011my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $ISDST) =localtime (); Print $year;p rint "\ n"; #111print strftime ("%y-%m-%d%h:%m:%s\n", localtime ()); #2011-07-14 12:26:01

Three C #
1tick = nanosecond

using system;using system.collections.generic;using system.linq;using System.Text;      Namespace mytest{class Program {static void Datetimetest () {DateTime DT2 = DateTime.Now; Console.WriteLine (DT2.      Ticks); Console.WriteLine (DT2.    ToString ("mm/dd/yyyy hh:mm:ss")); } static DateTime?      Convertperltimetodatetime (String perltime) {DateTime? dt = null;      Perl time variable:seconds from 1970.01.01 00:00:00 string SDT = Perltime;      Long Ldt = 0; if (long. TryParse (SDT, out Ldt)) {Long ldt2 = new DateTime (1970, 1, 1).         Ticks + LDT * 1000 * 1000 * 10;        DT = new DateTime (LDT2, datetimekind.local); Console.WriteLine (dt.      Value.tostring ("mm/dd/yyyy hh:mm:ss"));    } return DT;      } static void Main (string[] args) {datetimetest ();      Convertperltimetodatetime ("1309423883"); 634462479788396720//07/14/2011 01:46:18//06/30/2011 08:51:23}} 

Four Python

Python is similar to Perl, and time is the number of seconds starting January 1, 1970.

Import timeisotimeformat= '%y-%m-%d%x ' # seconds from 1970.01.01 00:00:00t = Time.time () print (t) print time.strftime ( Isotimeformat,time.localtime (t)) #1310623143.12#2011-07-14 13:59:03 (YEAR,MON,DAY,HOUR,MIN,SEC,WDAY,YDAY,ISDST) = Time.localtime () print (year) print (Time.strftime (Isotimeformat, Time.localtime ())) #2011 #2011-07-14 13:59:03
  • Related Article

    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.