cambiar fecha de PDA

08/10/2004 - 09:11 por Antonio S. | Informe spam
Hola a todos.
Me gustaria saber si es posible cambiar la fecha de mi
PDA por programa. Estoy desarrolando una aplicacion en
evb y me hace falta cambiar la fecha de 'sistema' para
determinadas operaciones.

Gracias.

Preguntas similare

Leer las respuestas

#1 José Miguel Torres
08/10/2004 - 14:07 | Informe spam
Aqui va una clase que permite cambiar y obtener la hora mediante APIs

using System;

using System.Runtime.InteropServices;

namespace PInvokeLibrary

{

/// <summary>

/// Allows the user to get/set the system time.

/// </summary>

public class Time

{

/// <summary>

/// This structure represents a date and time using individual members for

/// the month, day, year, weekday, hour, minute, second, and millisecond.

/// </summary>

public struct SYSTEMTIME

{

/// <summary>

/// Specifies the current year.

/// </summary>

public ushort wYear;

/// <summary>

/// Specifies the current month; January = 1, February = 2, and so on.

/// </summary>

public ushort wMonth;

/// <summary>

/// Specifies the current day of the week; Sunday = 0, Monday = 1, and so
on.

/// </summary>

public ushort wDayOfWeek;

/// <summary>

/// Specifies the current day of the month.

/// </summary>

public ushort wDay;

/// <summary>

/// Specifies the current hour.

/// </summary>

public ushort wHour;

/// <summary>

/// Specifies the current minute.

/// </summary>

public ushort wMinute;

/// <summary>

/// Specifies the current second.

/// </summary>

public ushort wSecond;

/// <summary>

/// Specifies the current millisecond.

/// </summary>

public ushort wMilliseconds;

}

/// <summary>

/// This function retrieves the current system date and time. The system
time

/// is expressed in Coordinated Universal Time (UTC).

/// </summary>

/// <param name="lpSystemTime">[out] Pointer to a SYSTEMTIME structure to

/// receive the current system date and time.</param>

[DllImport("coredll.dll")]

public extern static void GetSystemTime(ref SYSTEMTIME lpSystemTime);

/// <summary>

/// This function sets the current system time and date. The system time is

/// expressed in Coordinated Universal Time (UTC).

/// </summary>

/// <param name="lpSystemTime">[in] Pointer to a SYSTEMTIME structure that

/// contains the current system date and time.</param>

/// <returns></returns>

[DllImport("coredll.dll")]

public extern static uint SetSystemTime(ref SYSTEMTIME lpSystemTime);

/// <summary>

/// Run a test of the Time class.

/// </summary>

/// <param name="showLine">Delegate called to show debug information</param>

public static void TestProc()

{

DateTime dt = DateTime.UtcNow.ToLocalTime();

Console.Write(String.Format("Current Time: {0}:{1:00}:{2:00} {3}", dt.Hour >
12 ? dt.Hour - 12 : dt.Hour, dt.Minute, dt.Second, dt.Hour > 12 ? "PM" :
"AM"));

SYSTEMTIME st = new SYSTEMTIME();

GetSystemTime(ref st);

Console.Write("Adding 1 hour...");

st.wHour = (ushort)(st.wHour + 1 % 24);

if (SetSystemTime(ref st) == 0)

Console.Write("FAILURE: SetSystemTime failed");

dt = DateTime.UtcNow.ToLocalTime();

Console.Write(String.Format("Current Time: {0}:{1:00}:{2:00} {3}", dt.Hour >
12 ? dt.Hour - 12 : dt.Hour, dt.Minute, dt.Second, dt.Hour > 12 ? "PM" :
"AM"));

Console.Write("Setting time back...");

st.wHour = (ushort)(st.wHour - 1 % 24);

if (SetSystemTime(ref st) == 0)

Console.Write("FAILURE: SetSystemTime failed");

dt = DateTime.UtcNow.ToLocalTime();

Console.Write(String.Format("Current Time: {0}:{1:00}:{2:00} {3}", dt.Hour >
12 ? dt.Hour - 12 : dt.Hour, dt.Minute, dt.Second, dt.Hour > 12 ? "PM" :
"AM"));

}

}

}



Saludos


José Miguel Torres
jtorres_diaz~~ARROBA~~terra.es
http://jmtorres.blogspot.com

"Antonio S." escribió en el mensaje
news:050f01c4ad06$06fc17d0$
Hola a todos.
Me gustaria saber si es posible cambiar la fecha de mi
PDA por programa. Estoy desarrolando una aplicacion en
evb y me hace falta cambiar la fecha de 'sistema' para
determinadas operaciones.

Gracias.

Respuesta Responder a este mensaje
#2 Antonio.S
08/10/2004 - 18:21 | Informe spam
Gracias por tu respuesta, pero estoy programando en
eMbedded visual basic y entiendo que lo que me mandas es
para evc ++. Es facil trasladar lo que me mandas para evb?

De nuevo, gracias



Aqui va una clase que permite cambiar y obtener la hora


mediante APIs

using System;

using System.Runtime.InteropServices;

namespace PInvokeLibrary

{

/// <summary>

/// Allows the user to get/set the system time.

/// </summary>

public class Time

{

/// <summary>

/// This structure represents a date and time using


individual members for

/// the month, day, year, weekday, hour, minute, second,


and millisecond.

/// </summary>

public struct SYSTEMTIME

{

/// <summary>

/// Specifies the current year.

/// </summary>

public ushort wYear;

/// <summary>

/// Specifies the current month; January = 1, February =


2, and so on.

/// </summary>

public ushort wMonth;

/// <summary>

/// Specifies the current day of the week; Sunday = 0,


Monday = 1, and so
on.

/// </summary>

public ushort wDayOfWeek;

/// <summary>

/// Specifies the current day of the month.

/// </summary>

public ushort wDay;

/// <summary>

/// Specifies the current hour.

/// </summary>

public ushort wHour;

/// <summary>

/// Specifies the current minute.

/// </summary>

public ushort wMinute;

/// <summary>

/// Specifies the current second.

/// </summary>

public ushort wSecond;

/// <summary>

/// Specifies the current millisecond.

/// </summary>

public ushort wMilliseconds;

}

/// <summary>

/// This function retrieves the current system date and


time. The system
time

/// is expressed in Coordinated Universal Time (UTC).

/// </summary>

/// <param name="lpSystemTime">[out] Pointer to a


SYSTEMTIME structure to

/// receive the current system date and time.</param>

[DllImport("coredll.dll")]

public extern static void GetSystemTime(ref SYSTEMTIME


lpSystemTime);

/// <summary>

/// This function sets the current system time and date.


The system time is

/// expressed in Coordinated Universal Time (UTC).

/// </summary>

/// <param name="lpSystemTime">[in] Pointer to a


SYSTEMTIME structure that

/// contains the current system date and time.</param>

/// <returns></returns>

[DllImport("coredll.dll")]

public extern static uint SetSystemTime(ref SYSTEMTIME


lpSystemTime);

/// <summary>

/// Run a test of the Time class.

/// </summary>

/// <param name="showLine">Delegate called to show debug


information</param>

public static void TestProc()

{

DateTime dt = DateTime.UtcNow.ToLocalTime();

Console.Write(String.Format("Current Time: {0}:{1:00}:


{2:00} {3}", dt.Hour >
12 ? dt.Hour - 12 : dt.Hour, dt.Minute, dt.Second,


dt.Hour > 12 ? "PM" :
"AM"));

SYSTEMTIME st = new SYSTEMTIME();

GetSystemTime(ref st);

Console.Write("Adding 1 hour...");

st.wHour = (ushort)(st.wHour + 1 % 24);

if (SetSystemTime(ref st) == 0)

Console.Write("FAILURE: SetSystemTime failed");

dt = DateTime.UtcNow.ToLocalTime();

Console.Write(String.Format("Current Time: {0}:{1:00}:


{2:00} {3}", dt.Hour >
12 ? dt.Hour - 12 : dt.Hour, dt.Minute, dt.Second,


dt.Hour > 12 ? "PM" :
"AM"));

Console.Write("Setting time back...");

st.wHour = (ushort)(st.wHour - 1 % 24);

if (SetSystemTime(ref st) == 0)

Console.Write("FAILURE: SetSystemTime failed");

dt = DateTime.UtcNow.ToLocalTime();

Console.Write(String.Format("Current Time: {0}:{1:00}:


{2:00} {3}", dt.Hour >
12 ? dt.Hour - 12 : dt.Hour, dt.Minute, dt.Second,


dt.Hour > 12 ? "PM" :
"AM"));

}

}

}



Saludos


José Miguel Torres
jtorres_diaz~~ARROBA~~terra.es
http://jmtorres.blogspot.com

"Antonio S."


escribió en el mensaje
news:050f01c4ad06$06fc17d0$
Hola a todos.
Me gustaria saber si es posible cambiar la fecha de mi
PDA por programa. Estoy desarrolando una aplicacion en
evb y me hace falta cambiar la fecha de 'sistema' para
determinadas operaciones.

Gracias.





.

email Siga el debate Respuesta Responder a este mensaje
Ads by Google
Help Hacer una preguntaRespuesta Tengo una respuesta
Search Busqueda sugerida