What is a timestamp ?

Time stamp (timestamp), It's usually a sequence of characters , Uniquely identify the time of a moment . Digital time stamp technology is a variant application of digital signature technology .

reflection : In short, it's based on the documents hash Summary generated after encryption and time voucher generated by time , Its value is from 1970 year 1 month 1 Japan 8 The total number of milliseconds of the time from the point to the present

stay Objective-C How to convert a timestamp to NSDate?


NSTimeIntervaltime=[str doubleValue];

NSDate*detaildate=[NSDate dateWithTimeIntervalSince1970:time];


reflection : Use this function , Passing timestamps double You can get NSDate Time

How to convert the current time to a timestamp ?

NSDate *datenow =[NSDate date];// present time , You can output it to see what the format is

NSTimeZone *zone = [NSTimeZone systemTimeZone];

NSInteger interval = [zone secondsFromGMTForDate:datenow];

NSDate *localeDate = [datenow dateByAddingTimeInterval: interval];

NSString *timeSp = [NSString stringWithFormat:@"%d", (long)[localeDate timeIntervalSince1970]];

NSLog(@"timeSp:%@",timeSp); // The value of the timestamp

reflection : According to the current time and the time zone where the system is located, we can get the Interval, And then get the time after validation localeDate, Last [localeDate timeIntervalSince1970] The time and 1970 The difference between years , That's the timestamp

How to format output NSDate?

NSDateFormatter*formatter = [[NSDateFormatter alloc]init];

[formattersetDateFormat:@"yyyy year MM month dd Japan "];

NSDate *date =[formatter stringFromDate:detaildate];


reflection : Create a NSDateFormatter class , Then pass on a NSDate that will do .“yyyyMMddHHMMss” They represent year, year, day, hour, minute and second respectively

-( NSString *)timeStamp:( NSString *)data
     // Time stamp
     NSDateFormatter *formatter = [[ NSDateFormatter alloc] init] ;
     [formatter setDateStyle: NSDateFormatterMediumStyle ];
     [formatter setTimeStyle: NSDateFormatterShortStyle ];
     [formatter setDateFormat:@ "YYYY-MM-dd HH:mm:ss" ]; // ---------- Set the format you want ,hh And HH The difference between : respectively 12 hourly ,24 hourly
     NSTimeZone * timeZone = [ NSTimeZone timeZoneWithName:@ "Asia/Shanghai" ];
     [formatter setTimeZone:timeZone];
     // The method of time stamp to time
     NSString *str = [ NSString stringWithFormat:@ "%@" ,data];
     NSTimeInterval time =[str doubleValue];
     NSDate *confromTimesp = [ NSDate dateWithTimeIntervalSince1970: time ];
     //NSLog(@"1383523892  = %@",confromTimesp);
     NSString *confromTimespStr = [formatter stringFromDate:confromTimesp];
     //NSLog(@"confromTimespStr =  %@",confromTimespStr);
     NSString *timeString =[confromTimespStr substringWithRange: NSMakeRange (0,10)];
     return timeString;

IOS More about timestamps

  1. iOS Timestamp conversion

    Developing iOS The program , Sometimes you need to adjust the time format to the format you want , This time we can use NSDateFormatter Class to deal with . for example : // Instantiate a NSDateFormatter object NSDateForma ...

  2. iOS Time stamp

    The timestamp was used once , To sum up : 1. stay Terminal Get the timestamp under : date +%s The original document to be hung on the server side , Convenient for developers to download , Use the time stamp as the file name to distinguish . 2. Get the timestamp under the program : NSDate * n ...

  3. iOS Time stamp converted to time

    NSString *str=";// Time stamp NSTimeInterval time=[str doubleValue]+;// Because of the time difference 8 Hours == 28800 sec NSDate ...

  4. iOS The issue of timestamps

    - (NSString *)timeWithTimeIntervalString:(NSString *)timeString { // Format time NSDateFormatter* formatte ...

  5. iOS Time stamp and time interchange , Calculate the number of days between two dates

    /*  * Get the timestamp of the current system time  */ +(NSInteger)getNowTimestamp;   /**  * Get the current time  */ + (NSString *)getNowTimeTampF ...

  6. iOS Time stamp to today , In the morning , Afternoon , What day , A few months and a few days , Bless The Child

    There is chat function in the project , The boss converted the chat time to QQ Chat time in the same format , I studied it , To analyze QQ Chat format time Code : The time of the session list display If you need to convert to 24 hourly , Need to use HH // Time display content ...

  7. ios Time stamp current time Reciprocal transformation

    1. I'm making a webservice When the interface of , Asked to pass a time stamp , And then it started to Google Look for 2. There are two problems , One , The current time is converted to a timestamp , Two , The difference between the current time obtained and the system time 8 Hours One , turn ...

  8. iOS Standard time and time stamp are converted to each other

    iOS Standard time and time stamp are converted to each other (2012-07-18 17:03:34) Reprint ▼ label : ios Time stamp Standard time Format Set up conversion gossip classification : iPhone Development Set the time display format :     NS ...

  9. iOS Development time stamp and time NSDate, Time zone conversion , Chinese characters and UTF8,16 Base conversion

    http://blog.sina.com.cn/s/blog_68661bd80101njdo.html label : ios Time stamp ios Development timestamps ios16 Conversion from decimal to Chinese ios Development utf8 Transfer to Chinese ios ...

Random recommendation

  1. JSON Study note 1 —— Some interact with the mobile terminal to produce JSON Method of data

    /**     * The return of the test JSon Method , Formal ones don't work      * @author MrHandler     * @param reqCode     * @param joinStr     * ...

  2. C Standard Library Series limits.h

    limits.h Be similar to float.h, It defines the range of values for some column types . Limit value , In other words, the value of the type cannot be greater than the upper bound or less than the lower bound of the type value : glibc The macro defines the value of : # define MB_LEN ...

  3. ios Hardware coding

    video-videoToolbox: http://www.cnblogs.com/sunminmin/p/4976418.html audio-AudioToolbox: http://blog. ...

  4. android Java BASE64 Encoding and decoding one : Basics

    I'm doing it today Android There was a problem with the project , The requirement is to upload a picture to the server , It is required that the pictures be transformed into pictures and put in exile json In a string . Something like that : {"name":"jike&q ...

  5. love H5

    I don't want to think whether I can become famous or not. Since I have chosen the front end, I just concentrate on silence I don't want to win applause because I love IT You have to step forward bravely I don't want to think about whether the road ahead will be at a dead end. Since the goal is the future, the only thing left to us now is sweat I don't think about success ...

  6. Spring aop Note parameter description

    stay spring AOP in , Need to use AspectJ Pointcut expression language to define pointcut .  About Spring AOP Of AspectJ Tangent point , The most important thing is Spring Support only AspectJ Cut point indicator (pointcut ...

  7. 【NLP】Recurrent Neural Network and Language Models

    0. Overview What is language models? A time series prediction problem. It assigns a probility to a s ...

  8. C# Get the client IP Address

    client ip:Request.ServerVariables.Get("Remote_Addr").ToString(); Client hostname :Request.ServerVariables ...

  9. linux gcc nginx

    1. install GCC[root@rekfan.com opt]# rpm -ivh cpp-4.1.2-48.el5.i386.rpm[root@rekfan.com opt]# rpm -ivh kern ...

  10. SparkGraphx Calculate the... Of the specified node N Degree relation node

    Go straight to the code : package horizon.graphx.util import java.security.InvalidParameterException import horizon.gra ...