Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Question: localtime()

Question: localtime()

Scheduled Pinned Locked Moved C / C++ / MFC
c++helpquestioncsharpvisual-studio
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Y Offline
    Y Offline
    Yonggoo
    wrote on last edited by
    #1

    I am trying to compile a project written in Visual C++ 6 in Visual Studio 2005. And I have an error, saying error C2664: 'localtime' : cannot convert parameter 1 from 'long *' to 'const time_t *' Below is the snippet of the file long totalSeconds = (long)(dSeconds +.5); struct tm *myTime = localtime(&totalSeconds);//Convert to local tim Anybody can help me? Yonggoo

    C 1 Reply Last reply
    0
    • Y Yonggoo

      I am trying to compile a project written in Visual C++ 6 in Visual Studio 2005. And I have an error, saying error C2664: 'localtime' : cannot convert parameter 1 from 'long *' to 'const time_t *' Below is the snippet of the file long totalSeconds = (long)(dSeconds +.5); struct tm *myTime = localtime(&totalSeconds);//Convert to local tim Anybody can help me? Yonggoo

      C Offline
      C Offline
      cmk
      wrote on last edited by
      #2

      Short answer: The prototype for localtime is: struct tm *localtime(const time_t *timer); You are passing a long* not a time_t*. Longer answer: time_t is a long in 32-bit OS's but a __int64 in 64-bit OS's. As time_t has been a long for a long time (no pun intended) many developers found it more convenient to just use a long. In VS2005 time_t is a __int64 unless _USE_32BIT_TIME_T is defined. So, in reality you are passing a long* to a function expecting a __int64*. Just use time_t, there is a reason it is defined as a distinct type. e.g. time_t totalSeconds = (time_t)(dSeconds +.5); struct tm *myTime = localtime(&totalSeconds); ...cmk Save the whales - collect the whole set

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups