For suppose we have 166667777 of file then we want to convert into time stamp how to convert it in talend
in a tjava just paste this code :
Date myDate= new Date(Long.parseLong("1081157732") * 1000);
System.out.println(myDate) ;
SimpleDateFormat jdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String java_date = jdf.format(myDate);
System.out.println(java_date) ;
Since you didn't tell us your pattern just see what fits your requirement in the console
Don't forget this import in advanced settings :
import java.util.*;
import java.text.SimpleDateFormat ;
Here is the output :
[statistics] connected
Mon Apr 05 11:35:32 CEST 2004
2004-04-05 11:35:32
[statistics] disconnected
If you are wanting to get the the actual timestamp here how it is done
put in the tJava :
long epoch = Instant.now().toEpochMilli();
System.out.println(epoch);
LocalDate ld = Instant.ofEpochMilli(epoch).atZone(ZoneId.systemDefault()).toLocalDate();
System.out.println(ld);
LocalDateTime ldt = Instant.ofEpochMilli(epoch).atZone(ZoneId.systemDefault()).toLocalDateTime();
System.out.println(ldt);
And as always don't forget the import :
import java.text.SimpleDateFormat ;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
your output would be :
[statistics] connected
1638973017921
2021-12-08
2021-12-08T15:16:57.921
[statistics] disconnected
Related
*
import datetime
import pywhatkit
x = datetime.datetime.now()
time= x.strftime("%X")
hour= time[0:2]
min= time[3:5]
lan= hour, min+1
pywhatkit.sendwhatmsg(f"+918849152549","Geeks For Geeks!",lan) # this shows erroe because of lan variable.
print("Msg sent sucessfully")
I cannot get any NSE Symbol data from the AlphaVantage, they return always empty array.
Query:
https://www.alphavantage.co/query?function=TIME_SERIES_INTRADAY&symbol=NSE:TITAN&apikey=Q134IXR7RVWU5AQL&outputsize=full&interval=1min
Response:
{}
A month back the same query was returning data.
Looks something has changed on the AlphaVantage server end recently.
Your help is much appreciated in advance!
Try this
import pandas as pd
import json
import requests
import datetime
from pandas import DataFrame
from datetime import datetime as dt
from alpha_vantage.timeseries import TimeSeries
stock_ticker = 'SPY'
api_key = 'Q134IXR7RVWU5AQL'
ts = TimeSeries (key=api_key, output_format = "pandas")
data_daily, meta_data = ts.get_intraday(symbol=stock_ticker, interval ='1min', outputsize ='full')
print(data_daily)
The output for me looks like this
I have a set of dates stored as UTC in my database, when I import them in Salesforce using the tSalesforceOutput:
If I run the import from my machine, they get the wrong timezone
If I run the import from a server which is in UTC, they get the correct timezone.
Is Talend/Salesforce API using the local timezone? How can I prevent this?
Salesforce will allways convert datetime from user timezone to UTC before to store them.
To avoid any problem, the simpler is to fix the user timezone used for the Salesforce connection to GMT and to explicitly convert each datetime to this timezone before to call any tSalesforceOutputXxxx component.
Here is a routine you can use for this purpose:
package routines;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;
public class dateConversion {
public static String convertToGmt(String strDate, String timezone) throws Exception
{
if (strDate == null || timezone == null)
return null;
// Convert strDate from any valid TimeZone such as Europe/Paris to GMT
// strDate is expected to be formatted as "yyyy-MM-ddTHH:mm:ssZ"
SimpleDateFormat indfm = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
indfm.setTimeZone(TimeZone.getTimeZone(timezone));
Date inDate = indfm.parse(strDate);
SimpleDateFormat outdfm = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
outdfm.setTimeZone(TimeZone.getTimeZone("GMT"));
String s = outdfm.format(inDate);
return s;
}
}
Hope this helps.
TRF
I cant seem to convert a date in milliseconds (1488520800000) extracted from JSON and put into a variable into a formatted date (2017-03-02). Here's my code:
import java.text.*;
import java.util.*;
SimpleDateFormat source = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
SimpleDateFormat target = new SimpleDateFormat("yyyy-MM-dd");
Date date = source.parse(vars.get("varReviewDatevalue"));
String newDate = target.format(date);
vars.put("varFormattedReviewdateValue",newDate);
Here's the error I get:
ERROR - jmeter.util.BeanShellInterpreter: Error invoking bsh method: eval Sourced file: inline evaluation of: ``import java.text.*; import java.util.*; log.info("value for variable: 14885208 . . . '' : Typed variable declaration : Method Invocation source.parse
What's weird is that I got similar code to work fine for an extracted date like: March 2, 2017. I can't figure out why the date represented in mills is not converting to a date. Any ideas?
I was using the wrong jmeter element. This post helped me alot: JMeter: Converting extracted time stamp value to date format
I put this code into a JSR223 Sampler and everything worked
import java.text.*;
long timeStamp = Long.parseLong(vars.get("varReviewDatevalue"));
Date date = new Date(timeStamp);
DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
TimeZone tzInAmerica = TimeZone.getTimeZone("America/Denver");
formatter.setTimeZone(tzInAmerica);
String dateFormatted = formatter.format(date);
vars.put("varFormattedReviewdateValue", dateFormatted);
log.info(dateFormatted);
log.info(vars.get("varFormattedReviewdateValue"));
I have to find the last date of the last month
I am using a Groovy Script
I can get the date part ok but now I have to turn it into a String in the form yyyyMMdd.
Code so far (and yes it works)
import java.util.GregorianCalendar;
import java.util.Calendar;
import java.util.Date;
Calendar aCalendar = Calendar.getInstance();
// add -1 month to current month
aCalendar.add(Calendar.MONTH, -1);
// set actual maximum date of previous month
aCalendar.set(Calendar.DATE,aCalendar.getActualMaximum(Calendar.DAY_OF_MONTH));
//read it
lastDateOfPreviousMonth = aCalendar.getTime();
This returns the date in timestamp form
20160229 105925.240
Now I need to extract 20160229 from the timestamp as a string
I've tried just about everything...
If this is running on Java 8, you can use the new Java Time classes:
import java.time.LocalDate
import java.time.format.DateTimeFormatter
import java.time.temporal.TemporalAdjusters
String date = LocalDate.now()
.minusMonths(1)
.with(TemporalAdjusters.lastDayOfMonth())
.format(DateTimeFormatter.ofPattern("yyyyMMdd"))
If this is Java 7 or Java 6, you can use Calendar and a bit of Groovy:
String date = Calendar.instance.with {
add(MONTH, -1)
set(DAY_OF_MONTH, getActualMaximum(DAY_OF_MONTH))
time
}.format('yyyyMMdd')