Jump to content

Recommended Posts

Posted

Olá Pessoal!

Estou precisando desenvolver um programa que o usuário digita uma data de inicio e uma data de fim no padrão dd/mm/aaaa 00:00:00.

Com o objetivo de iniciar uma contagem por segundos da data inicial fornecida até a data final, depois gerar um arquivo TXT para salvar essas informações

04/11/2012 23:59:56,

04/11/2012 23:59:57,

04/11/2012 23:59:58,

04/11/2012 23:59:59,

05/11/2012 00:00:00,

05/11/2012 00:00:01,

05/11/2012 00:00:02,

05/11/2012 00:00:03,

Obrigado!

Posted

Não consigo somar os segundos à data mesmo o Txt é tranquilo

Public Class Form1
Dim a As DateTime = Date.Now
Dim b As DateTime = CDate("01-01-1970 00:00:00")



Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
	MessageBox.Show(DateDiff(DateInterval.Second, a, b).ToString)
End Sub
Posted

Algo assim?

(cria um timer ativo com o intervalo de 1000 ms)

' Variaveis gerais do form, que vão controlar a data/hora inicial, final e atual
Dim startDateTime As DateTime
Dim endDateTime As DateTime
Dim currenttDateTime As DateTime

' Ao iniciar o form
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
' Define as datas pretendidas
startDateTime = New DateTime(2014, 2, 24, 11, 0, 0)
endDateTime = New DateTime(2014, 2, 24, 11, 0, 20)
currenttDateTime = startDateTime

End Sub

' Evento chamado a cada segundo
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
' Se ainda não passou a data final
If currenttDateTime <= endDateTime Then
	' Mostra a data/hora atual
	Console.WriteLine(currenttDateTime)
	' Incrementa um segundo
	currenttDateTime = currenttDateTime.AddSeconds(1)
Else
	' Se passou a data final, pára o timer
	Timer1.Enabled = False
End If
End Sub
Posted

Ah ok, pensei que era para atualizar o ficheiro de segundo a segundo.

Dim startDateTime As New DateTime(2014, 2, 24, 11, 0, 0)
Dim endDateTime As New DateTime(2014, 2, 24, 11, 1, 0)
Dim currenttDateTime As DateTime = startDateTime
'
Using sw As New System.IO.StreamWriter("ficheiro.txt")
   '
   While currenttDateTime <= endDateTime
       '
       sw.WriteLine(currenttDateTime)
       '
       currenttDateTime = currenttDateTime.AddSeconds(1)
   End While
End Using
  • Vote 1
Posted

Algo assim?

Dim startDateTime As New DateTime(2014, 2, 24, 11, 0, 0)
Dim endDateTime As New DateTime(2014, 2, 24, 11, 35, 0)
Dim currenttDateTime As DateTime = startDateTime
'
Using sw As New System.IO.StreamWriter("ficheiro.txt")
'
While currenttDateTime <= endDateTime
	'
	sw.WriteLine(currenttDateTime)

	'
	If (currenttDateTime = startDateTime.AddMinutes(5)) Then
		currenttDateTime = currenttDateTime.AddMinutes(25)
	Else
		currenttDateTime = currenttDateTime.AddSeconds(1)
	End If
End While
End Using
Posted

Dim startDateTime As New DateTime(2012, 11, 4, 23, 7, 34) '(2012, 11, 3, 4, 18, 0)

Dim endDateTime As New DateTime(2013, 11, 22, 13, 48, 53) '(2013, 11, 22, 13, 48, 53)

Dim currenttDateTime As DateTime = startDateTime

Dim contador As Integer

Using sw As New System.IO.StreamWriter("Phaze_Concatenado.txt")

While currenttDateTime <= endDateTime

contador = 0

While contador <= 299

sw.WriteLine(currenttDateTime)

currenttDateTime = currenttDateTime.AddSeconds(1)

contador = contador + 1

End While

currenttDateTime = currenttDateTime.AddMinutes(25)

sw.WriteLine(contador)

End While

End Using

MessageBox.Show("Arquivo Gerado com Sucesso")

Acabou ficando dessa maneira mesmo, obrigado pela Força

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.