C-language implementation of a simple example of a Fu Jing Unix timestamp _c language

Source: Internet
Author: User

The C language implements the character Fu Jing Unix timestamp, which needs to be converted to a TM type before getting its Unix timestamp. Attached implementation code:

#include <stdio.h>
#include <time.h>
int strtotime (char datetime[])
{
struct TM tm_time;
int unixtime;
Strptime (DateTime, "%y-%m-%d%h:%m:%s", &tm_time);

Unixtime = Mktime (&tm_time);
return unixtime;
}


Attach a few time related functions, make a note:

//Current time


char* get_curr_time ()
{
char* strtime = (char *) malloc (sizeof (char) * );
memset (strtime, 0, sizeof (char) *20);
time_t now;
Time (&now);
Strftime (Strtime, "%y-%m-%d%h:%m:%s", Gmtime (&now));
printf ("Info:current time%s\n", strtime);
return strtime;
}


The current time's UNIX timestamp


int get_curr_unixtime (void)
{
time_t now;
int unixtime = time (&now);
return unixtime;
}


Character to Unix time stamp


int strtotime (char datetime[])
{
struct TM tm_time;
int unixtime;
Strptime (DateTime, "%y-%m-%d%h:%m:%s", &tm_time);

Unixtime = Mktime (&tm_time);
return unixtime;
}

Above the C language implementation of the word Fu Jing Unix Timestamp Simple example is a small series to share all the content, hope to give you a reference, but also hope that we support cloud habitat community.

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.