View previous topic :: View next topic |
Author |
Message |
lucasromeiro
Joined: 27 Mar 2010 Posts: 167
|
Converting seconds to date |
Posted: Tue Apr 26, 2016 7:33 am |
|
|
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: 1934 Location: Norman, OK
|
|
Posted: Tue Apr 26, 2016 9:33 am |
|
|
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
|
|
Posted: Tue Apr 26, 2016 10:12 am |
|
|
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: 1934 Location: Norman, OK
|
|
Posted: Tue Apr 26, 2016 10:16 am |
|
|
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
|
|
Posted: Tue Apr 26, 2016 10:28 am |
|
|
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
|
|
Posted: Tue Apr 26, 2016 10:29 am |
|
|
there is no other way to do what I want? |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1934 Location: Norman, OK
|
|
Posted: Tue Apr 26, 2016 10:45 am |
|
|
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
|
|
Posted: Tue Apr 26, 2016 2:59 pm |
|
|
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
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19520
|
|
Posted: Thu Apr 28, 2016 2:00 am |
|
|
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. |
|
|
|