CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Converting seconds to date

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
lucasromeiro



Joined: 27 Mar 2010
Posts: 167

View user's profile Send private message

Converting seconds to date
PostPosted: Tue Apr 26, 2016 7:33 am     Reply with quote

Hello. I need to convert seconds date!
UTC to local time
day
month
year
hour
minute
second
Can someone help me?
I tried to use the time.c library, but could not. because of the error.
Can someone help me?

dyeatman



Joined: 06 Sep 2003
Posts: 1924
Location: Norman, OK

View user's profile Send private message

PostPosted: Tue Apr 26, 2016 9:33 am     Reply with quote

Did you include time.h before time.c?
It would help if you read the header in time.c
Quote:
/// Contains common time routines that can be used by several
timebases, and the runtime code needed for time.h. See time.h for
documentation.

_________________
Google and Forum Search are some of your best tools!!!!
lucasromeiro



Joined: 27 Mar 2010
Posts: 167

View user's profile Send private message

PostPosted: Tue Apr 26, 2016 10:12 am     Reply with quote

dyeatman wrote:
Did you include time.h before time.c?
It would help if you read the header in time.c
Quote:
/// Contains common time routines that can be used by several
timebases, and the runtime code needed for time.h. See time.h for
documentation.


yes, it includes Time.h
these photo errors not leave.
I do not understand why this happens!

Is there any other way to do iso?
convert seconds readable date?
dyeatman



Joined: 06 Sep 2003
Posts: 1924
Location: Norman, OK

View user's profile Send private message

PostPosted: Tue Apr 26, 2016 10:16 am     Reply with quote

It compiles just fine for me with both includes under 5.056
Please give your version and show your code from the start to where time.c is included...
_________________
Google and Forum Search are some of your best tools!!!!
lucasromeiro



Joined: 27 Mar 2010
Posts: 167

View user's profile Send private message

PostPosted: Tue Apr 26, 2016 10:28 am     Reply with quote

dyeatman wrote:
It compiles just fine for me with both includes under 5.056
Please give your version and show your code from the start to where time.c is included...

Code:

#include "18LF2685.h"
#device ADC = 16

#FUSES NOWDT       //No Watch Dog Timer
#FUSES WDT128      //Watch Dog Timer uses 1:128 Postscale
#FUSES NOBROWNOUT  //No brownout reset
#FUSES NOPBADEN    //PORTB pins are configured as digital I/O on RESET
#FUSES NOLVP       //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES BBSIZ1K     //1K words Boot Block size
#FUSES NOXINST     //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#FUSES PROTECT     //Code protected from reads
#use delay(crystal = 20000000)
#use rs232(baud = 115200, parity = N, xmit = PIN_C6, rcv = PIN_C7, bits = 8) //, stream = Modem)
#use i2c(Master, Fast, sda = PIN_C4, scl = PIN_C3)

//127900

//INCLUDES
//#define LOADER_END 5247  //bootloader
//#include "bootloader.h"  //bootloader
#include "ds1307.c"  //Relogio
#include "mcp342X.c" //ADC mcp3424
#include "241025.c"  //Memoria 128.000 bytes
#include "STRING.h"  //Memoria
//#include "stdlib.h"
#include "timestamp.c" //transforma o timestamp em unix (contagem de segundos desde 1/1/15) em int 32
#include <time.h>
#include <time.c>  //conversao de timestamp unix para data localtime



VERSION: 5.008

including the time.h show this:

lucasromeiro



Joined: 27 Mar 2010
Posts: 167

View user's profile Send private message

PostPosted: Tue Apr 26, 2016 10:29 am     Reply with quote

there is no other way to do what I want?
dyeatman



Joined: 06 Sep 2003
Posts: 1924
Location: Norman, OK

View user's profile Send private message

PostPosted: Tue Apr 26, 2016 10:45 am     Reply with quote

First of all, you have something wrong in your program so you need to resolve the issues not look for other solutions.

The message your getting now indicates you have a coding error before time.h, possibly in timestamp.c (BTW, what is this?)

Try moving string.h, time.h and time.c (in that order) up to right after the word //INCLUDES and above all the rest of the includes.

BTW, your utility includes stdio, time, string etc need to always come before the drivers...
_________________
Google and Forum Search are some of your best tools!!!!
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Tue Apr 26, 2016 2:59 pm     Reply with quote

Hi,

First, I agree with dyeatman that you need to understand, and solve, your current problem first before moving on.....

Having said that, I must say that this is an odd request! So, you are saying that you have a UTC time in seconds (Unix time?) that you need to convert to local time? Is that correct? What is the source of the Unix time? Can you show us a sample?

IOW, give us more background, and describe more fully what you are trying to do. That will better enable us to offer help and solutions! For example, I have a function that takes UTC time from a GPS receiver, and converts it to local time based on a user selectable UTC offset. Is that anything like you are trying to do?

John
_________________
John

If it's worth doing, it's worth doing in real hardware!
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Tue Apr 26, 2016 9:28 pm     Reply with quote

International time standards - as opposed to absolute time reference sources

for french speakers TAI and UTC become UCT and IAT

So UTC ==UCT

Universal coordinated time

http://www.timeanddate.com/time/aboututc.html

and a nice entry here that explains key
reference time relationships.
including the GPS "19 second difference"

https://en.wikipedia.org/wiki/Coordinated_Universal_Time


poster needs to explain what he wants to do and post some code.
Ttelmah



Joined: 11 Mar 2010
Posts: 19348

View user's profile Send private message

PostPosted: Thu Apr 28, 2016 2:00 am     Reply with quote

Yes.

The first key point is though that the standard Unix time.c, ported to CCS, is supplied with CCS, and includes the code to convert date/time, to seconds UTC, and back. It works if used properly, and so he should get this working.

GPS to date/time, has the potential problem of leap seconds, but is relatively easy to fix provided you are prepared to input the offset (as ezflyr has said). He presumably just includes the leap value in his input (I too have had to do this, with you simply inputting the local timezone, and leap seconds).

Handling GPS leap seconds really is simplest handled by just inputting them. Problem is that they are unpredictable (the shift is changed by things like El Nino events), so there is no formula for these. My code stores the last value input, and uses this if it is not updated.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group